I have this output from my 1st query, and i wont know the rank row for each session over contactID and service ID.
Each ContactID + ServiceID need group to obtain rank over sessionID by createdDate Desc.
My data:
My query
SELECT ROW_NUMBER() OVER (PARTITION BY ServiceID, ContactID , SESSIONID ORDER BY [Created] DESC) AS rn1,
RANK() OVER (PARTITION BY ServiceID, ContactID , SESSIONID ORDER BY [Created] DESC) AS rn2,
DENSE_RANK() OVER (PARTITION BY ServiceID, ContactID , SESSIONID ORDER BY [Created] DESC) AS rn3
FROM #TABLE
My output its not what I need.
I need some like this:
1条答案
按热度按时间8ftvxx2r1#
Looks like the date is irrelevant to the calculation, you just want
DENSE_RANK
sorted by sessionID