我有两个名为A,B的表。我编写SQL查询以从A,B中检索数据。它如下:
SELECT A.No ,
A.ItemCode,
case when B.Year = 1 then SUM(B.Sale_Amount) end as "1Year",
case when B.Year = 2 then SUM(B.Sale_Amount) end as "2Year",
case when B.Year = 3 then SUM(B.Sale_Amount) end as "3Year"
FROM A
LEFT OUTER JOIN B ON B.ID = A.CODE
GROUP BY
A."No",
A."ItemCode",
B."Year"
这给出了以下输出:
但我需要将这三行选择为两行,如下所示:
答案 0 :(得分:0)
这是正确答案
retrieveHumidDataAssign()
FROM A
左外联接B B.ID = A.CODE
GROUP BY A.No,A.ItemCode