我遇到了一个场景,我对如何让它发挥作用感到困惑。
我如何从SUM
结果中COUNT
两个不同的组?
Select Count(VisitID), Types
From Customers
Group by Types;
结果如下:
Type VisitID
A 10
B 20
C 1
我希望结果如下:
Type VisitID
A+C 11
感谢。
答案 0 :(得分:0)
例如CTE:
WITH CustomerCounts ([Count], [Types])
AS
(
Select Count(VisitID), [Types]
from Customers
Group by [Types]
)
Select SUM([Count])
From CustomerCounts
Where [Types] in ('A', 'C')
答案 1 :(得分:0)
试试这个
仅选择您想要的类型,然后使用pivot将行转换为列,然后像这样汇总列SELECT pv.[a] + pv.[c] from (..........)