sql - How to get colDate row for every colA where max(denseRank) - 1 -
i trying solve following:
cola coldate denserank ------------------------------- 2015-06-10 1 2015-06-09 2 b 2015-06-10 1 b 2015-06-09 2 b 2015-06-08 3
and want result
a 2015-06-10 1 b 2015-06-09 2
is possible query or can through t-sql? can example of solution? thank in advance...
how this? (should work sql server 2005+)
select cola, coldate, denserank ( select cola, coldate, denserank, row_number() on (partition cola order denserank desc) rn yourtable ) x x.rn = 2
edit: changed use row_number()
instead of rank()
.
also, didn't specify, assuming given value of cola
, can't have duplicate denserank
values.
Comments
Post a Comment