partitioning - SQL "over" partition WHERE date between two values -
i have query partitions , ranks "note" records, grouping them id_task (users add notes each task). want rank notes date, want restrict they're ranked between 2 dates.
i'm using sql server 2008. far select looks this:
select note.id, note.id_task, note.[days], note.[date], row_number() on (partition id_task order cast([date] date), edited asc) rank note note.locked = 1 , note.deleted = 0
now, assume if put clause @ bottom, although they'll still have ranks, might or might not item rank 1, might filtered out. there way can partition records , ignoring of others? partition sub-query guess.
the intention use rank number find recent note each task, in query. in query i'll join result rank = 1.
row_number()
operates after where
. you'll row 1.
for example:
declare @t table (id int) insert @t values (3), (1), (4) select row_number() on (order id) @t id > 1
this prints:
1 2
Comments
Post a Comment