[Quote=引用 60 楼 hdyes 的回复:]
引用 56 楼 aloxy 的回复:
SELECT 编码, 通用名, 单位, SUM(数量) AS 数量, MAX(进价) AS 最高进价, MIN(进价)
AS 最低进价, SUM(数量 * 进价) / SUM(数量) AS 加权价, SUM(金额) AS 金额
FROM dbo.v_rk
GROUP BY 编码, 单位, 通用名
假如:
期初库存表 a
进货表 b
退货表 c
select sum(sum_money)/sum(sum_qty) as jqcb
from
(select
(select 'kc',sum(数量) as sum_qty,sum(数量*单价) as sum_money from a
where qcmonth = @month)
union
(select 'jh',sum(数量) as sum_qty,sum(数量*单价) as sum_money from b
where fsdate between @begindate and @enddate)
union
(select 'th',sum(数量) as sum_qty,sum(数量*单价) as sum_money from c
where fsdate between @begindate and @enddate)
from dual) z
[Quote=引用 56 楼 aloxy 的回复:]
SELECT 编码, 通用名, 单位, SUM(数量) AS 数量, MAX(进价) AS 最高进价, MIN(进价)
AS 最低进价, SUM(数量 * 进价) / SUM(数量) AS 加权价, SUM(金额) AS 金额
FROM dbo.v_rk
GROUP BY 编码, 单位, 通用名
[/Quote]