Oracle 中不同计数的总和
Sum of Distinct count in Oracle
我有以下 table:
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
中从上述 table 中获取 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
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
我有以下 table:
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
中从上述 table 中获取 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
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