sql - How do i return the Most Recent Event in a series of same title events -


i have situation need able return recent of occurrence may or may not have occurred more once. instance:

each time product moved position position b, recorded (from_function) / (to_function) along operator , timestamp. on rare instances - re-work required , unit show same / instance different time stamps.

i calculating age in each position datediff, how return recent in scenario?

i got down if there no group clause return date needed max(route_date_time)

however,,,

the total qry many lines long aggregate functions group necessary, how can return 1 line needed recent date.

i've found rank() useful in finding oldest/newest dates. i'd try like:

with cte       (select [fields]         rank() over(partition [product] order [datetime] desc) rankno     table)  select [fields], [aggregates] cte     rankno = 1 group     [fields] 

this rank product/datetime 1 being recent datetime , increasing there.

if provide table structure , sql version i'll update query needed provide more detailed answer.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -