在根据过滤器值执行查询时,是否可以将列拆分为两列。
例如,给定数据库架构
x varchar
a integer
b 0,1
我可以执行查询
select x , sum(a) as asum from t group by x
最终会以
结束 x | asum
---+-----
...| ...
现在我想为a b等于0和1
计算不同的和所以结果集应该是
x | as for x = 0 | as for x = 1
---+--------------+---------------
...| ... | ...
原因我可以执行
select x , sum(a) as asum, b as as from t group by x, b
但这需要额外的应用程序端转换
答案 0 :(得分:3)
在大多数数据库中,您可以进行条件聚合:
select x,
sum(case when b = 0 then a else 0 end) as a_0,
sum(case when b = 1 then a else 0 end) as a_1
from t
group by x;
Voltdb似乎支持case
(here),所以这应该有效。