我正在努力获得“活跃产品系列”的计数(*)总和。 2个日期之间。这是我的一点。
我想总结一下“产品线”的活跃程度'柱。我遗漏了其他Where子句来简化这个问题。
SELECT mfr_id as 'Manufacturer ID', COUNT(*) AS 'Product lines Active'
FROM database.LabReport
Where (rpt_upload_dt BETWEEN '2012-01-01' and '2012-12-31' )
GROUP BY mfr_id
Order by mfr_id
答案 0 :(得分:2)
尝试使用子查询。它的一个解决方案可能不是最好的。
SELECT SUM(Product lines Active) AS 'sum'
FROM
(SELECT mfr_id as 'Manufacturer ID', COUNT(*) AS 'Product lines Active'
FROM database.LabReport
Where (rpt_upload_dt BETWEEN '2012-01-01' and '2012-12-31' )
GROUP BY mfr_id) AS x
答案 1 :(得分:1)
正如鲍比所指出的,这是最简单的解决方案:
SELECT COUNT(*)AS'产品系列有效'
FROM database.LabReport 哪里(rpt_upload_dt BETWEEN' 2012-01-01'和' 2012-12-31')
答案 2 :(得分:0)
您将无法在另一个函数之上使用聚合函数..
试试这个..
WITH CTE AS (
SELECT mfr_id as 'Manufacturer ID', COUNT(*) AS Product_lines_Active
FROM database.LabReport
Where (rpt_upload_dt BETWEEN '2012-01-01' and '2012-12-31' )
GROUP BY mfr_id
)
SELECT SUM(Product_lines_Active)
FROM CTE
OR 直接使用聚合
SELECT COUNT(*) AS Product_lines_Active
FROM database.LabReport
Where (rpt_upload_dt BETWEEN '2012-01-01' and '2012-12-31' )