Teradata 计数特定记录和总记录
Teradata Counting specific records and total records
Table :我有以下 table 我想从中查询具有特定条件的某些记录。我想查询 Len x Wdth x ht < 16 x 16 x 24 的 PO_Num 的数量。除此之外,我还想要另一列用于总 PO 数量。
我想要的结果应该是这样的:
Result
最好的方法是什么?
Select c1, c2 from
(Select count(*) as c1 from yourtable where wt > 15 and ht > 16 and len > 17 ) as count1,
(Select count(*) as c2 from yourtable) as total
您可以使用 conditional aggregation
。我对 teradata
不太熟悉,但您使用“len”作为列名,它是某些数据库中的保留关键字。确保它不会给您带来麻烦。
select count(*) as count1,
sum(case when wt > 15 and ht > 16 and len > 17 then 1 else 0 end) as count2
from yourtable;
Table :我有以下 table 我想从中查询具有特定条件的某些记录。我想查询 Len x Wdth x ht < 16 x 16 x 24 的 PO_Num 的数量。除此之外,我还想要另一列用于总 PO 数量。
我想要的结果应该是这样的: Result
最好的方法是什么?
Select c1, c2 from
(Select count(*) as c1 from yourtable where wt > 15 and ht > 16 and len > 17 ) as count1,
(Select count(*) as c2 from yourtable) as total
您可以使用 conditional aggregation
。我对 teradata
不太熟悉,但您使用“len”作为列名,它是某些数据库中的保留关键字。确保它不会给您带来麻烦。
select count(*) as count1,
sum(case when wt > 15 and ht > 16 and len > 17 then 1 else 0 end) as count2
from yourtable;