going off of last question: complex grouping in sql query…
in each grouping, i'd grab row highest 'step' value.
this query came in last question:
select a.*, b.* ( select request_id tablea group request_id having max(page_views) <= 0 , max(step) <= 2 ) sumq inner join tablea on sumq.request_id = a.request_id inner join tableb b on a.request_id = b.id
that returns:
id request_id page_views step name phone ---------------------------------------------------------------- 8 3 0 0 jacob clark 434-343-434 9 3 0 1 jacob clark 434-343-434 10 4 0 0 alex smith 222-112-2112 11 4 0 1 alex smith 222-112-2112 12 4 0 2 alex smith 222-112-2112
which wanted, however, realized in each group (group request_id) need row highest 'step' value. how can modify existing query return only:
id request_id page_views step name phone ---------------------------------------------------------------- 9 3 0 1 jacob clark 434-343-434 12 4 0 2 alex smith 222-112-2112
?
then include step
in logic:
select a.*, b.* (select request_id, max(step) maxstep tablea group request_id having max(page_views) <= 0 , max(step) <= 2 ) sumq inner join tablea on sumq.request_id = a.request_id , sumq.maxstep = a.step inner join tableb b on a.request_id = b.id;
Comments
Post a Comment