SqlServer 多表查询

select t1.ID as ID,t1.NAME as NAME,t1.PLACE as PLACE,t1.soPrice as SO_PRICE,t1.soCount as SO_COUNT,
t2.sroPrice as SRO_PRICE,t2.sroCount as SRO_COUNT,(t1.soPrice*t1.soCount - t2.sroPrice*t2.sroCount) as PROFIT 
 from (select pro.ID ,pro.NAME ,pro.PLACE ,so.PRICE as soPrice,sum(so.COUNT) as soCount from PRODUCT pro
 left join SO_ITEM so on pro.ID = so.PRODUCT_ID
 where pro.DELFLAG = '0' group by pro.ID ,pro.NAME ,pro.PLACE ,so.PRICE) t1 left join
 (select pro.ID ,pro.NAME ,pro.PLACE ,sro.PRICE as sroPrice,sum(sro.COUNT)as sroCount from PRODUCT pro
 left join SRO_ITEM sro on pro.ID = sro.PRODUCT_ID
 where pro.DELFLAG = '0' group by pro.ID ,pro.NAME ,pro.PLACE ,sro.PRICE ) t2 on t1.ID = t2.ID

posted on 2012-03-31 18:47  吐个泡泡  阅读(219)  评论(0编辑  收藏  举报

导航