次のクエリがあります。
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 句に含めていないため、これは実行されません。ただし、それを行うと、次のように同じ顧客の 2 行が表示されます。
Customer1 0.00 120.00
Customer1 500.00 0.00
それ以外の
Customer1 500.00 120.00
助言がありますか?