0
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;

如何将总和添加到 count(X) 语句的末尾作为计算计数总和的另一列,或者在行的底部?

我试过了

Union All
Select 'SUM' X (table)
From Table

但这是不正确的

4

1 回答 1

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
于 2012-12-05T19:03:46.870 回答