我正在尝试编写一份有多个计数的报告:
SELECT
C.REGION,
COUNT (C.id) AS 'No of customers',
COUNT (C.id) AS 'No of new customers',
COUNT (C.id) As 'No of waiting customers',
COUNT (C.id) As 'Total No of help available'
FROM CUSTOMER C
INNER JOIN CUSTOMERPARAMETER CP ON C.ID=CP.ID
WHERE (C.DATEOFBIRTH IS NULL)
GROUP BY C.REGION
问题是我的每个计数都由不同的查询填充。创建多个查询报告的最佳方法是什么?
它不允许我为每个计数写一个select语句......我需要为每个计数写一个不同的查询。但它不会让我。
答案 0 :(得分:0)
如果没有关于表格架构的更多信息,我可以指出正确的方向:
SELECT C.REGION,
(SELECT COUNT(*) FROM <...>) AS 'No of customers',
(SELECT COUNT(*) FROM <...>) AS 'No of new customers',
(SELECT COUNT(*) FROM <...>) As 'No of waiting customers',
(SELECT COUNT(*) FROM <...>) As 'Total No of help available'
FROM CUSTOMER C ....
将<...>
替换为每列所需的条件,然后设置。
请参阅这些子类的参考:Subqueries Used in Place of an Expression
希望这有帮助