日期:2014-05-17 浏览次数:20589 次
select
TH004 as 品号,
avg(TH015) as 采购进货数,
TH008 as 单位,
TG003 as 日期
from PURTH left join PURTG
on TG001=TH001 and TG002=TH002
where TH030='Y' and TH015<>0
group by
TH004,TG003,TH008
select
TJ004 as 品号,
avg(TJ009) as 采购退货数,
TJ007 as 单位,
TI003 as 日期
from PURTJ left join PURTI
on TJ001=TI001 and TJ002=TI002
where TJ020='Y' and TJ009<>0
group by
TJ004,TI003,TJ007
SELECT 品号 ,
SUM(采购进货数) 采购进货数 ,
SUM(采购退货数) 采购退货数 ,
SUM(采购退货数) - SUM(采购退货数) AS [现存数] ,
单位 ,
日期
FROM ( SELECT TH004 AS 品号 ,
0 AS 采购退货数 ,
AVG(TH015) AS 采购进货数 ,
TH008 AS 单位 ,
TG003 AS 日期
FROM PURTH
LEFT JOIN PURTG ON TG001 = TH001
AND TG002 = TH002
WHERE TH030 = 'Y'
AND TH015 <> 0
GROUP BY TH004 ,
TG003 ,
TH008
UNION ALL
SELECT TJ004 AS 品号 ,