Create Table DBONE AS (
Select distinct count(X) as Count, Y, Z
FROM Schema.Table
Where (Schema.Table.X like '%Retire%' or Schema.Table.X like '%Obsolete%')
Group by (X, Y, Z)
)
ORDER BY X, Y, Z asc;
如何计算计数(X)语句末尾的总和作为计算计数总和的另一列,或者行的底部?
我已经尝试了
Union All
Select 'SUM' X (table)
From Table
但这是不正确的
答案 0 :(得分:0)
您的查询没有真正意义。计数总是返回“1”,因为您按X分组。此外,在使用group by时不需要distinct。
您可能需要:
Select Y, Z, count(*) as count,
sum(count(*)) over () as TotalCount
FROM Schema.Table
Where (Schema.Table.X like '%Retire%' or Schema.Table.X like '%Obsolete%')
Group by Y, Z