是否可以在同一个查询中执行多个计数?

时间:2015-10-27 19:02:26

标签: mysql sql sas

是否可以在sql / sas中的同一查询中进行多次计数?我正在做以下事情,显然我在sku级别获得了响应,因为这是最详细的级别。我希望所有这些都与发行要约代码区别开来:

SELECT DISTINCT
   t1.ISSUANCE_OFFER_CODE,
   (COUNT(t1.SKU)) AS COUNT_of_SKU,
   (COUNT(t1.ASSORTMENT)) AS COUNT_of_ASSORTMENT,
   (COUNT(t1.PRODUCT_GROUP)) AS COUNT_of_PRODUCT_GROUP,
   (COUNT(t1.DIVISION_NAME))
FROM WORK.OFFERS t1
GROUP BY t1.ISSUANCE_OFFER_CODE;

1 个答案:

答案 0 :(得分:1)

DISTINCT添加到COUNT s:

SELECT

t1.ISSUANCE_OFFER_CODE,
(COUNT(t1.SKU)) AS COUNT_of_SKU,
(COUNT(DISTINCT t1.ASSORTMENT)) AS COUNT_of_ASSORTMENT,
(COUNT(DISTINCT t1.PRODUCT_GROUP)) AS COUNT_of_PRODUCT_GROUP, 
(COUNT(DISTINCT t1.DIVISION_NAME))

FROM WORK.OFFERS t1

GROUP BY t1.ISSUANCE_OFFER_CODE;