我正在寻找以下输出
通常是一个矩阵,顾客数量超过购买的商品和产品组,即。计算超过2个属性(项目和产品组)
我尝试了下面的代码,但之后它只给了我
片段,
count (distinct customer_id) over (Partition by customer_id) as Customer_ID
,count (distinct customer_shipment_item_id) Over (Partition by customer_id) as customer_items
,count (distinct product_group) Over (Partition by customer_id) as customer_product_groups
你能解释一下这是怎么回事吗?
答案 0 :(得分:0)
试试这个。除非我不明白你在寻找什么,否则你不需要Partition By子句。
count (distinct customer_id) as Customer_ID
,count (distinct customer_shipment_item_id) as customer_items
,count (distinct product_group) as customer_product_groups
答案 1 :(得分:0)
我认为这样的事情会给你你想要的东西:
SELECT COUNT(customer_id) Customer_ID, customer_items, customer_product_groups
FROM
(SELECT customer_id, COUNT(DISTINCT customer_shipment_item_id) as customer_items,
COUNT(DISTINCT product_group) as customer_product_groups
FROM TABLENAME
JOIN <YOUR JOINS>
WHERE customer_id IN (SELECT customer_ID FROM <YOUR JOINS> WHERE customer_shipment_item_id = x)
GROUP BY customer_id
) a
GROUP BY customer_items, customer_product_groups