mysql - Query to find result with max rundate with max horizon -
mysql - Query to find result with max rundate with max horizon -
table info looks like:
eventid | mpid | rundate | horizon | otherdata 1 | 1 | 23-jun-2014 | 360 | other value 1 | 1 | 23-jun-2014 | 365 | pther value 1 | 1 | 23-jun-2014 | 300 | pther value 1 | 1 | 22-jun-2014 | 700 | pther value 1 | 2 | 23-jun-2014 | 400 | other value 1 | 2 | 23-jun-2014 | 340 | oth 2 | 3 | 23-jun-2014 | 360 | pther value 2 | 3 | 23-jun-2014 | 300 | pther value 2 | 3 | 22-jun-2014 | 365 | pther value
i want select max rundate each event , marketplace grouping , select max horizon among grouping , print entire row.
desired result :
eventid | mpid | rundate | horizon | otherdata 1 | 1 | 23-jun-2014 | 365 | pther value 1 | 2 | 23-jun-2014 | 400 | other value 2 | 3 | 23-jun-2014 | 360 | pther value
please allow me know sql query this.
i tried next query not working:
select * dsie_result_overalls id in ( select k.id dsie_result_overalls k, ( select a.event_id, a.marketplaceid, max(a.horizon) horizon dsie_result_overalls a, ( select id, event_id, marketplaceid, max(rundate) rundate dsie_result_overalls grouping event_id, marketplaceid ) b a.event_id = b.event_id , a.marketplaceid = b.marketplaceid , a.rundate = b.rundate grouping a.event_id, a.marketplaceid ) l k.event_id = l.event_id , k.marketplaceid = l.marketplaceid , k.horizon = l.horizon );
it selects multiple rundate max horizon.
try query
select t.* tbl t bring together ( select max(s.horizon) maxhorizon,max(s.rundate) dte,s.eventid,s.mpid tbl s bring together ( select t1.eventid,max(t1.rundate) maxrundate,t1.mpid tbl t1 grouping t1.eventid,t1.mpid ) jr on s.rundate = jr.maxrundate , s.eventid = jr.eventid , s.mpid = jr.mpid grouping s.mpid,s.eventid )r on t.horizon = r.maxhorizon , t.eventid = r.eventid , t.mpid = r.mpid , t.rundate = r.dte
fiddle demo
output be
eventid | mpid | rundate | horizon | otherdata 1 | 1 | 23-jun-2014 | 365 | pther value 1 | 2 | 23-jun-2014 | 400 | other value 2 | 3 | 23-jun-2014 | 360 | pther value
mysql sql max
Comments
Post a Comment