我在postgresql中有一个有趣的问题。
select sum(value1) as v1,
sum(value2) as v2,
sum(value3) as v3,
sum(value4) as v4,
sum(value5) as v5,
...
from (select * from test limit 0)x;
结果:
v1 | v2 | v3 | v4 | v5 | ...
-----+-----+-----+-----+-----+--...
| | | | | ...
(1 row)
预期:(0行)。
真相:( 1排)。
我不想得到空行。 如何才能获得此案例的正确结果。 感谢。
答案 0 :(得分:1)
您可以使用having
子句过滤掉空值:
select sum(id)
from (
select *
from test limit 0
) x
having sum(id) is not null;