palce department 大箱箱量 (big) 小箱箱量(small) 理货等级(gread)
二期卡口 慈溪余姚拆箱点 0 98 C
二期卡口 慈溪余姚拆箱点 173 18 B
二期卡口 慈溪余姚拆箱点 20 30 D
二期卡口 慈溪余姚拆箱点 30 20 A
二期卡口 慈溪余姚拆箱点 30 20 A
招商 宁波 18 20 D
招商 宁波 18 20 A
招商 宁波 18 20 D
招商 宁波 18 20 B
招商 宁波 18 20 C
这个我是
select b.palce,b.department,sum(b.big),sum(b.small),a.gread from a,b
我想得到这样的结果:
palce department 大箱箱量 (big) 小箱箱量(small) A B C D
二期卡口 慈溪余姚拆箱点 253 186 100 191 98 50
招商 宁波 90 100 38 38 38 76
(理货等级有四个 A B C D )
大家有没有好办法呀
------解决方案--------------------
SELECT palce, department,SUM(big),SUM(small),SUM(decode(gread, 'A ',big+small,0)),
SUM(decode(gread, 'B ',big+small,0)),SUM(decode(gread, 'C ',big+small,0)),SUM(decode(gread, 'C ',big+small,0)) FROM A
你写的sql我不知道b是什么意思?
select b.palce,b.department,sum(b.big),sum(b.small),a.gread from a,b
------解决方案--------------------
可以用以下的sql语句来实现:
select a1.place,a1.department,a1.BigAmount,a1.SmallAmount,a1.A,b1.B,c1.C,d1.D from
(select place,department,BigAmount,SmallAmount,A from (
select place,department,sum(big) as BigAmount,sum(tsmall) as SmallAmount,
gread,sum(big)+sum(tsmall) as A from TestSQL where gread= 'A '
group by gread,place,department)) a1 left join (select B,place from (select place,department,