SQL, choosing max date and if two results have a max date, choose the one with the max weight -
SQL, choosing max date and if two results have a max date, choose the one with the max weight -
id | date_i | weight 1 | 10/04/2014 08:13:05 | 10 2 | 02/04/2014 08:13:05 | 15 3 | 08/04/2014 08:13:05 | 10 4 | 13/04/2014 08:13:05 | 12 5 | 13/04/2014 08:13:05 | 10
my sql request request should give me row 4.
select id, max(date_i) mytable m m.weight > (select m2.weight mytable m2 having max(date_i));
try this:
select y.id, x.maxdate, x.maxweight ( select a.maxdate, max(b.weight) maxweight ( select max(date_i) maxdate mytable )a inner bring together mytable b on a.maxdate = b.date_i grouping a.maxdate ) x inner bring together mytable y on x.maxweight = y.weight
demo here
sql
Comments
Post a Comment