日期:2014-05-17 浏览次数:20396 次
--如表A
DM XMMC A B
1 Q 10.00 20.00
2 A 10.00 20.00
3 Z 10.00 20.00
4 W 10.00 20.00
5 S 10.00 20.00
--表B
DM XMMC C D
1 Q 5.00 20.00
2 A 5.00 20.00
4 W 5.00 20.00
5 S 5.00 20.00
--结果
DM XMMC A B C D
1 Q 10.00 20.00 5.00 20.00
2 A 10.00 20.00 5.00 20.00
3 Z 10.00 20.00 0.00 0.00 --表B没有的在表A显示 数值0.00即可
4 W 10.00 20.00 5.00 20.00
5 S 10.00 20.00 5.00 20.00
select a.*, C=isnull(b.C,0), D=isnull(b.D,0) from ta a left join tb b on a.DM=b.DM --and a.XMMC=b.XMMC
select a.*,isnull(b.C,0),isnull(b.D,0) from Ta as a left join Tb as b
on a.DM=b.DM and a.XMMC=b.XMMC