首页 新闻 会员 周边 捐助

SQL SUM显示问题

0
悬赏园豆:5 [已解决问题] 解决于 2013-06-05 16:19

---单个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了为什么呢?

新麦穗的主页 新麦穗 | 初学一级 | 园豆:82
提问于:2013-06-05 16:05
< >
分享
最佳答案
0

 SELECT June.JuneData,July.JulyData
 
 FROM  
 ( SELECT  SUM(point) AS JuneData 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) AS JulyData FROM  dbo.ShopPoint WHERE     ShopPoint.createtime BETWEEN '2009-07-01 ' AND'2009-08-01 '
  AND ShopPoint.sid = '240' AND ShopPoint.point > 0)  AS July

新麦穗 | 初学一级 |园豆:82 | 2013-06-05 16:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册