按客户划分不同的项目

partition by customer for distinct items

selectcustomer_id, row_number()over(按客户id划分 按日期排序)作为 rn 来自 table

Item Id相同时如何得到相同的rn?

以下无效: #1 select customer_id, row_number()over(按客户id、商品id划分 按日期排序)作为 rn 来自 table

我们可以尝试用DENSE_RANK代替row_numberwindow函数

If the optional PARTITION BY clause is present, the rankings are reset for each group of rows. Rows with equal values for the ranking criteria receive the same rank

select customer_id, DENSE_RANK() over(partition by customer id order by date) as rn 
from table