Mysql query relating to count and date time -
i have table 'transaction' contains columns transaction_id, sender_id,amount, date_time,payee_id . want find transactions more 5 made sender_id in 1 day single sender. tried mysql> select * transaction sender_id count() =5 , datedif() =1;
i think query helpful you.
select sender_id, count(sender_id) count `transaction` group sender_id, date(date_time) having count>5
this return list of sender_ids have more 5 transactions if need list of transactions need this
select t.* ( select sender_id, count(sender_id) count `transaction` group sender_id, date(date_time) having count>5 ) senders inner join `transaction` t on t.sender_id=senders.sender_id
ps. performance recommend run second query on mysql server version 5.6.10 or higher
Comments
Post a Comment