[英]Row_Number and Partition
My data looks like this - 我的数据看起来像这样-
CALENDAR CLIENTID
20180801 178
20180802 178
20180803 578
The max(calendar)
for clientid
178
is 20180802
. 该max(calendar)
用于clientid
178
是20180802
。 How do I get the row_number for max(calendar)
per clientid
. 如何获取每个clientid
max(calendar)
的row_number。 In the case of client 178
, it would be 2 because it is the second row. 在客户端178
的情况下,它将是2,因为它是第二行。 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". 这是“行数”的最大值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.