SELECT d_main.Type,ItemGrade,ItmName,d_sub.ItmCode,
(CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type='E'
THEN sum(d_sub.Qty) ELSE 0 END) as f1,
(CASE WHEN d_sub.FulItmCode=item.ItmCode and d_main.Type='L'
THEN sum(d_sub.Qty) ELSE 0 END) as f2
from d_main, d_sub, item
where d_main.FullNo=d_sub.FullNo and
item.ItmCode = d_sub.ItmCode
group by d_main.Type,d_sub.ItmCode;
输出
d_main.Type ItemGrade ItmName d_sub.ItmCode f1 f2
----------- --------- ------- ------------- -- --
E A AAAAAA A005 5.000 0
E B BBBBBB B006 1.000 0
E C CCCCCC C015 3.050 0
L A AAAAAA A005 0 5.750
L B BBBBBB B006 0 8.000
我想要的预期结果和答案
A AAAAAA A005 5.000 5.750
B BBBBBB B006 1.000 8.000
C CCCCCC C015 3.050 0.000