表名:order
idd spgg sl
1 608 200
2 608 200
表名:orderMX
reidd spgg jhsl
1 608 100
返回结果:
idd spgg sl jhsl
1 608 200 100
2 608 200 0
--测试数据
declare @order table (idd int,spgg int,sl int)
insert into @order
select 1,608,200 union all
select 2,608,200
--测试数据
declare @orderMX table (reidd int,spgg int,jhsl int)
insert into @orderMX
select 1,608,100
select a.*,isnull(b.jhsl,0) as jhsl
from @order a left join @orderMX b on a.idd=b.reidd
/*
idd spgg sl jhsl
----------- ----------- ----------- -----------
1 608 200 100
2 608 200 0
*/
发表评论