我有以下查询:
select
ii.customer
, CONVERT(DECIMAL(20,2),ISNULL((Select SUM(gld.amount) where inv.inventorydepartmentid='B00H'),0.00)) AS CD
,CONVERT(DECIMAL(20,2),ISNULL((Select SUM(gld.amount) where inv.inventorydepartmentid='A00G'),0.00)) AS Cam
from
invoiceitemview ii with (nolock)
inner join
master m with(nolock) on m.masterid=ii.masterid
inner join
warehouse w with (nolock) on w.warehouseid=ii.warehouseid
inner join
category c on c.categoryid=m.categoryid
inner join
gl on gl.invoiceitemid=ii.invoiceitemid
inner join
inventorydepartment inv on inv.inventorydepartmentid = c.inventorydepartmentid
inner join
gldetail gld on gld.warehouseid = w.warehouseid and gl.glid = gld.glid
and m.masterid = gld.masterid
where
gl.gldate between @StartDate and @EndDate
and ii.status IN ('CLOSED', 'PROCESSED')
and w.warehouseid = '01'
and w.inactive <> 'T'
and ii.customerno = 'T1'
group by
ii.customer
但是,这不会运行,因为我没有包含inv.inventorydepartmentid
在 group by 子句中。但是,如果我这样做,那么它会显示同一客户的两行,如下所示:
Customer1 0.00 120.00
Customer1 500.00 0.00
代替
Customer1 500.00 120.00
有什么建议么?