文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>月份统计精简Sql

月份统计精简Sql

时间:2011-03-17  来源:懒人ABC

SELECT
Q1.ProductName
,(Q2.M1 & Power(2,OrderDate)) *  SaleVolume AS M1
,(Q2.M2 & Power(2,OrderDate)) *  SaleVolume AS M2
,(Q2.M3 & Power(2,OrderDate)) *  SaleVolume AS M3
,(Q2.M4 & Power(2,OrderDate)) *  SaleVolume AS M4
,(Q2.M5 & Power(2,OrderDate)) *  SaleVolume AS M5
,(Q2.M6 & Power(2,OrderDate)) *  SaleVolume AS M6
,(Q2.M7 & Power(2,OrderDate)) *  SaleVolume AS M7
,(Q2.M8 & Power(2,OrderDate)) *  SaleVolume AS M8
,(Q2.M9 & Power(2,OrderDate)) *  SaleVolume AS M9
,(Q2.M10 & Power(2,OrderDate)) *  SaleVolume AS M10
,(Q2.M11 & Power(2,OrderDate)) *  SaleVolume AS M11
,(Q2.M12 & Power(2,OrderDate)) *  SaleVolume AS M12
FROM
(
SELECT
T3.[name] AS ProductName
,datepart(MM, T2.orderdate) AS OrderDate
,SUM(ISNULL(T1.totalretailvalue,0.00)) AS SaleVolume
FROM [Order] T1
INNER JOIN
OrderPart T2
ON T1.id = T2.[orderno]
INNER JOIN
m_product T3
ON T2.collectionid = T3.id
WHERE T1.isdeleted = 0 AND T3.id = $ProductId$ AND datepart(YEAR, T2.orderdate) = $Year$
GROUP BY T3.[name],datepart(MM, T2.orderdate)
) Q1

CROSS JOIN
(
SELECT 1 AS M1,2 AS M2,4 AS M3,8 AS M4, 16 AS M5,32 AS M6,64 AS M7,128 AS M8, 256 AS M9, 512 AS M10, 1024 AS M11, 2048 AS M12
) Q2

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载