enter image description here Vertica SQL,用于按列获取数据,其中在具有不同条件的单个表中支持多个计数
1. select COUNT(*) as x from WORLDPOP
2. SELECT COUNT(*) as y FROM WORLDPOP WHERE COUNTRY LIKE '%i%'
OP
x y
10 2
答案 0 :(得分:2)
您需要条件聚合:
select count(*) as x,
sum(case when COUNTRY LIKE '%i%' then 1 else 0 end) as y
from WORLDPOP;
答案 1 :(得分:0)
有条件的聚合是必经之路。我更喜欢在Postgres兼容数据库(包括Vertica)中可用的较短语法:
select count(*) as x,
sum( (country like '%i%')::int ) as y
from WORLDPOP;