我有下表:
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中的上表中获得Total Distinct CUST_ID,TOTAL DISTINCT PRODUCT_ID
以下一个不起作用
SELECT SUM(COUNT(DISTINCT cust_id)), product_id
FROM CUST_PRODUCT_DTL
WHERE
GROUP BY product_id , cust_id
我期待的结果是 总独特Cust_id:3 唯一Product_id:3
答案 0 :(得分:4)
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