日期:2014-05-18 浏览次数:20524 次
select a..ProdudctCode,a.Descr, FOB=max(case when b.PriceListName='FOB' then Price else 0 end), WHO=max(case when b.PriceListName='WHO' then Price else 0 end), from 产品表 a join 体格表 b on a.ProductCode=b.ProductCode group by a.ProdudctCode,a.Descr
------解决方案--------------------
select C.ProductCode, C.Descr as ProductDescription, sum(FOB) as FOB, sum(WHO) as WHO
from
(
select A.ProdudctCode, A.Descr,
case when PriceListName = 'FOB' then Price else 0 end as FOB,
case when PriceListName = 'WHO' then Price else 0 end as WHO
from 产品表 A inner join 体格表 B on B.ProductCode = A.ProductCode
) C
group by C.ProdudctCode, C.Descr
------解决方案--------------------
select m.* , FOB = isnull((select Price from 体格表 n where n.ProductCode = m.ProdudctCode and n.PriceListName = 'FOB'),0), WHO = isnull((select Price from 体格表 n where n.ProductCode = m.ProdudctCode and n.PriceListName = 'WHO'),0) from 产品表 m
------解决方案--------------------
select a.ProdudctCode,a.Descr,
max(case when b.PriceListName='FOB' then Price else 0 end),
max(case when b.PriceListName='WHO' then Price else 0 end)
from 产品表 a
join 体格表 b on a.Descr=b.ProductCode
group by a.produdctcode, a.Descr