日期:2014-05-17 浏览次数:20716 次
SELECT SUM(TotalPrice) FROM NarukoEC.dbo.Orders AS o WHERE CreateTime BETWEEN '20110101' AND '20110131' AND o.TotalGoodsPrice>0 AND NOT EXISTS( SELECT 1 FROM NarukoEC.dbo.Orders WHERE state not in(0,5,7) AND CreateTime < '20110101' AND CustomerID = o.CustomerID )
SELECT SUM(TotalPrice) FROM NarukoEC.dbo.Orders AS o WHERE CreateTime BETWEEN '20110201' AND '20110228' AND o.TotalGoodsPrice>0 AND NOT EXISTS( SELECT 1 FROM NarukoEC.dbo.Orders WHERE state not in(0,5,7) AND CreateTime < '20110201' AND CustomerID = o.CustomerID )
SELECT SUBSTRING(CreateTime,5,2),SUM(TotalPrice) FROM NarukoEC.dbo.Orders AS o WHERE o.TotalGoodsPrice > 0 AND [state] IN ( 0, 5, 7 ) GROUP BY SUBSTRING(CreateTime,5,2)
------解决方案--------------------
SELECT DATEPART(mm , CreateTime) AS 月份 , SUM(TotalPrice) AS 合计 FROM NarukoEC.dbo.Orders AS o WHERE CreateTime BETWEEN '20110101' AND '20111231' AND o.TotalGoodsPrice > 0 AND state NOT IN (0 , 5 , 7) GROUP BY DATEPART(mm , CreateTime)