日期:2014-05-16 浏览次数:20555 次
SELECT SUM(CONVERT(money, yavg)) / SUM(CONVERT(int, DAYS)) AS yavg, FproductID, NF, FproductName, MarketID
FROM (SELECT SUBSTRING(CONVERT(varchar(10), DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GetDate) + 1, 0)), 20), 9, 9) AS DAYS,
SUBSTRING(CONVERT(varchar(10), DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GetDate) + 1, 0)), 20), 9, 9) * yuejunjia AS yavg,
SUBSTRING(CONVERT(varchar(10), DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(m, 0, GetDate) + 1, 0)), 20), 1, 4) AS NF, FproductID,
FproductName, MarketID
FROM (SELECT DISTINCT c.FproductName, b.GetDate, b.yuehuanbi, b.yuetongbi, b.yuejunjia, b.FproductID, b.MarketID
FROM dbo.ls_scb AS a INNER JOIN
dbo.ls_jgb AS b ON a.MarketID = b.MarketID INNER JOIN
dbo.ls_pzb AS c ON b.FproductID = c.FproductID) AS s) AS a
GROUP BY FproductID, NF, FproductName, MarketID
SELECT v1.NF, CAST(v1.yavg AS numeric(16, 2)) AS