sql - Get id of max value in group -
i have table , gather id of items each group max value on column have problem.
select group_id, max(time) mytable group group_id
this way correct rows need id:
select id,group_id,max(time) mytable group id,group_id
this way got rows. how achieve id of max value row time each group?
sample data
id = 1, group_id = 1, time = 2014.01.03 id = 2, group_id = 1, time = 2014.01.04 id = 3, group_id = 2, time = 2014.01.04 id = 4, group_id = 2, time = 2014.01.02 id = 5, group_id = 3, time = 2014.01.01
and should id: 2,3,5 thanks!
use working query sub-query, this:
select `id` `mytable` (`group_id`, `time`) in ( select `group_id`, max(`time`) `time` `mytable` group `group_id` )
Comments
Post a Comment