小编Rub*_*ten的帖子

将多个联合语句分组

我已经查看了整个网站,但找不到解决我的问题的方法。我试图尽可能地抽象它。

我的查询是这样的:

select sup, a, b, c, d
from
(
    select sup, a, 0, 0, 0 from x where y = 1 group by sup
    union
    select sup, 0, b, 0, 0 from x where y = 2 group by sup
    union
    select sup, a, 0, c, 0 from x where y = 3 group by sup
    union
    select sup, a, 0, 0, d from x where y = 4 group by sup
)
Run Code Online (Sandbox Code Playgroud)

这工作正常,我得到了我期望的结果。

我想要的是将这些结果分组在 sup 列中。当我GROUP …

db2 pivot

5
推荐指数
1
解决办法
1922
查看次数

标签 统计

db2 ×1

pivot ×1