mysql - Get latest record on group by -
i have table construction this:
id win bet userid date 1 win 1000 1 2014-11-12 19:15:34 2 win 1000 1 2014-11-12 19:15:49 3 loose 1000 1 2014-11-12 19:21:52
and run query this:
select u.username, sum(b.bet) totalwin, b.date, b.win blackjack_history b inner bring together users_main u on b.userid = u.id b.win = 'win' grouping b.userid order totalwin desc, limit 10
the probem when run query, returns row id 1 regarding date. how homecoming date id 2 instead? have tried using order by
not seem job
you don't want latest record. doing aggregation. so, utilize max()
:
select u.username, sum(b.bet) totalwin, max(b.date) date, b.win blackjack_history b inner bring together users_main u on b.userid = u.id b.win = 'win' grouping b.userid order totalwin desc limit 10;
mysql mysqli
No comments:
Post a Comment