现有三个table:Purchaser Header:放的有订单号、供应商、采购员的代码是主表
Purchaser Line:是上面表的明细有列出对应的订单号及采购每个产品的数量及单价金额。
Purchaser:放的是采购员的代码及对应这个代码的中文名称。
现想列出订单号及对应这个订单的总的数量及总的金额及采购员的中文名称。
用SQL该如何实现,下面的SQL没有写完,请各位帮忙补充,提出建议,多谢!
drop table #tempsales
SELECT cast(sum([Line Amount]) as decimal(10,2))as 'Amt',
cast(sum(quantity) as decimal(10,2))as 'Qty',
[Document No_] into #tempsales
FROM [WT$purchase line] group by [Document No_]
select a.Amt,a.Qty,a.[Document No_],b.[Pay-to Vendor No_],b.[Purchaser Code] from #tempsales as a inner join
[WT$purchase header]
as b on a.[Document No_]=b.[No_]
Purchaser Line:是上面表的明细有列出对应的订单号及采购每个产品的数量及单价金额。
Purchaser:放的是采购员的代码及对应这个代码的中文名称。
现想列出订单号及对应这个订单的总的数量及总的金额及采购员的中文名称。
用SQL该如何实现,下面的SQL没有写完,请各位帮忙补充,提出建议,多谢!
drop table #tempsales
SELECT cast(sum([Line Amount]) as decimal(10,2))as 'Amt',
cast(sum(quantity) as decimal(10,2))as 'Qty',
[Document No_] into #tempsales
FROM [WT$purchase line] group by [Document No_]
select a.Amt,a.Qty,a.[Document No_],b.[Pay-to Vendor No_],b.[Purchaser Code] from #tempsales as a inner join
[WT$purchase header]
as b on a.[Document No_]=b.[No_]
join
(
select 定单号,SUM(数量*单价)as 总量,SUM(数量)as 总量 from Line group by 定单号
) A on A.定单号=H.定单号
join Purchaser P on P.采购员号=H.采购员号