![](/img/trans.png)
[英]Count Distinct and Sum at different group levels in single Oracle query
[英]Sum of Distinct count in Oracle
我有下表:
CUST_PRODUCT_DTL
Cust_ID Product_ID QTY
1 10 5
2 10 2
3 10 5
1 11 5
2 12 1
我如何從Oracle 11 G的上表中獲得總不同的CUST_ID,總不同的PRODUCT_ID
下面的一個不起作用
SELECT SUM(COUNT(DISTINCT cust_id)), product_id
FROM CUST_PRODUCT_DTL
WHERE
GROUP BY product_id , cust_id
我正在查看的期望結果是:唯一的客戶總ID:3唯一的產品總ID:3
sum
不涉及,也不需要group by
。 您所需的輸出僅包含一行。 您只需要兩個計數區別:
select count(distinct cust_id) as total_distinct_cust_id,
count(distinct product_id) as total_distinct_prod_id
from cust_product_dtl
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.