Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

sql - Redshift: Incremental products ordered across marketplaces

I have a table, 'Customer_Orders' that basically lists the products purchased by customers across marketplaces (UK, DE, US etc). Here's a short overview of the table:

Cust_id marketplace product
1 UK A
1 UK B
1 DE A
1 US A
1 US C

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Are you trying to get the differences like this?

select cust_id, marketplace,
       (count(*) - max(case when marketplace = 'UK' then count(*) end) over (partition by cust_id)) as diff_from_uk
from Customer_Orders co
group by cust_id, marketplace;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...