原帖由 jzhua2006 于 2008-1-22 09:33 发表
select b.id,b.xm,nvl(hj.HJQK,0) HJQK,nvl(lj.LJQK,0) LJQK from st_boss b
left join
(
select count(*) HJQK,username from st_boss_other bo where bo.type = 'HJQK' group by username
) hj
on hj.username = b.username
left join
(
select count(*) LJQK,username from st_boss_other bo where bo.type = 'LJQK' group by username
) lj
on lj.username = b.username
结果
idxm HJQK LJQK
9867
臧正金
2
0
9868
陈晓均
0
0
我现在想把(HJQK,LJQK)相加起来,我用了sum(),但是不行!
还问下各位!这个怎么写呀!
select id,xm,hjqk+ljqk from (
select b.id,b.xm,nvl(hj.HJQK,0) HJQK,nvl(lj.LJQK,0) LJQK from st_boss b
left join
(
select count(*) HJQK,username from st_boss_other bo where bo.type = 'HJQK' group by username
) hj
on hj.username = b.username
left join
(
select count(*) LJQK,username from st_boss_other bo where bo.type = 'LJQK' group by username
) lj
on lj.username = b.username
)
|