你如何使用UNION
多个Common Table Expressions
?
我正在尝试将一些汇总数字放在一起,但无论我把它们放在哪里;
,我总是会得到一个错误
SELECT COUNT(*)
FROM dbo.Decision_Data
UNION
SELECT COUNT(DISTINCT Client_No)
FROM dbo.Decision_Data
UNION
WITH [Clients]
AS ( SELECT Client_No
FROM dbo.Decision_Data
GROUP BY Client_No
HAVING COUNT(*) = 1
)
SELECT COUNT(*) AS [Clients Single Record CTE]
FROM Clients;
我很欣赏在上面的示例中,我可以将单个CTE 移到开头,但我有许多 CTE 我想UNION