【发布时间】:2020-03-12 01:58:00
【问题描述】:
我在 redshift 中运行下面的代码。我想根据日期获得客户购买产品时的订单排名。每次购买都有唯一的ticketid,每个客户都有唯一的customer_uuid,每个产品都有唯一的product_id。下面的代码为所有排名返回 1,我不知道为什么。我的代码中是否有错误,或者红移中的日期字段排名是否有问题?有谁知道如何修改此代码以更正问题。
代码:
select customer_uuid,
product_id,
date,
ticketid
rank()
over(partition by customer_uuid,
product_id,
ticketid order by date asc) as rank
from table
order by customer_uuid, product_id
数据:
customer_uuid product_id ticketid date
1 2 1 1/1/18
1 2 2 1/2/18
1 2 3 1/3/18
输出:
customer_uuid product_id ticketid date rank
1 2 1 1/1/18 1
1 2 2 1/2/18 1
1 2 3 1/3/18 1
想要的输出:
customer_uuid product_id ticketid date rank
1 2 1 1/1/18 1
1 2 2 1/2/18 2
1 2 3 1/3/18 3
【问题讨论】:
标签: sql amazon-redshift window-functions