簡體   English   中英

Oracle中的不同總數

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM