SQL SUM显示问题
---单个SQL
1.
SELECT point FROM dbo.ShopPoint WHERE ShopPoint.createtime BETWEEN '2009-06-01 ' AND'2009-07-01 ' AND ShopPoint.sid = '240' AND ShopPoint.point > 0
SUM结果为 1097
2.
SELECT point FROM dbo.ShopPoint WHERE ShopPoint.createtime BETWEEN '2009-07-01 ' AND'2009-08-01 ' AND ShopPoint.sid = '240' AND ShopPoint.point > 0
SUM结果为1253
3.
组合起来的SQL
SELECT SUM(June.point) AS JuneData ,SUM(July.point) AS JulyData
FROM
( SELECT point FROM dbo.ShopPoint WHERE ShopPoint.createtime BETWEEN '2009-06-01 ' AND'2009-07-01 '
AND ShopPoint.sid = '240' AND ShopPoint.point > 0) AS June,
( SELECT point FROM dbo.ShopPoint WHERE ShopPoint.createtime BETWEEN '2009-07-01 ' AND'2009-08-01 '
AND ShopPoint.sid = '240' AND ShopPoint.point > 0) AS July
4.
SUM结果分别:3291,1253了为什么呢?
------解决方案--------------------SELECT * FROM
( SELECT sum(point) FROM dbo.ShopPoint WHERE ShopPoint.createtime BETWEEN '2009-06-01 ' AND'2009-07-01 '
AND ShopPoint.sid = '240' AND ShopPoint.point > 0) AS June,
( SELECT sum(point) FROM dbo.ShopPoint WHERE ShopPoint.createtime BETWEEN '2009-07-01 ' AND'2009-08-01 '
AND ShopPoint.sid = '240' AND ShopPoint.point > 0) AS July