My data looks like this -
CALENDAR CLIENTID
20180801 178
20180802 178
20180803 578
The max(calendar)
for clientid
178
is 20180802
. How do I get the row_number for max(calendar)
per clientid
. In the case of client 178
, it would be 2 because it is the second row. This is what I have so far -
select clientid,
ROW_NUMBER() OVER ( partition by clientid ORDER BY max(calendar) desc )
from STATS
group by clientid
You can just count the rows for each client:
select clientid, count(*)
from stats
group by clientid;
This is the maximum of the "row number".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.