我得到一个查询,该查询多次使用具有相同列和过滤器的同一个表,唯一改变的是手动给出的类型。我认为必须有更好的方法来做到这一点。
查询语句如下:
Select Column 1, Column 2, Sum(Column 3) AS Test, "First Query" AS "Type"
From Table X
Where Column 1 = "Fly"
Group by Column 1, Column 2
UNION ALL
Select Column 1, Column 2, Sum(Column 3) AS Test, "Second Query" AS "Type"
From Table X
Where Column 1 = "Fly"
Group by Column 1, Column 2
UNION ALL
Select Column 1, Column 2, Sum(Column 3) AS Test, "Third Query" AS "Type"
From Table X
Where Column 1 = "Fly"
Group by Column 1, Column 2
谢谢!
利用
可能 SELECT
Types
需要额外的FROM DUAL
或类似的,或者 DB2 使用另一种方法来选择标量值 - 测试。更新(从评论中复制)