日期:2014-05-18 浏览次数:20579 次
select a.*,isnull(b.jhsl,0) from [order] a left join orderMX b on a.idd =b.reidd
------解决方案--------------------
select idd,spgg,sl,isnull(jhsl,0)jhsl from order t1,orderMX t2 where t1.idd=t2.idd
------解决方案--------------------
select a.idd,a.spgg,a.sl,case when b.jhsl is null then 0 else b.jhsl end jhsl from order a left join orderMX b on a.idd=b.reidd
------解决方案--------------------
SQL code select t1.idd,t1.spgg,sl,isnull(jhsl,0)jhsl from order t1,orderMX t2 where t1.idd=t2.idd
------解决方案--------------------
--测试数据 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 */