有一条SQL语句如下 :  是计算用户的整积分 
     我 想求的是用户的整积分 , 不论时间段是多少,
      但只显示出在这个时间段有积分的用户
              该怎么写呢
SELECT userID, sum(Points) AS points
                  FROM Reward
                 where 
                    creationDate >= 1232088570051
                   and creationDate <= 1332088570051
                 GROUP BY userID
                 ORDER BY points DESC

解决方案 »

  1.   

    SELECT userID, sum(Points) AS points 
                      FROM Reward 
                    where 
                        creationDate >= 1232088570051 
                      and creationDate <= 1332088570051 and Points is not null
                    GROUP BY userID 
                    ORDER BY points DESC
      

  2.   


          我的意思是先求出总积分
                  表1   SELECT userID, sum(Points) AS points 
                      FROM Reward 
                    GROUP BY userID 
                    ORDER BY points DESC
                    表2    SELECT userID
                     FROM Reward 
      creationDate >= 1232088570051
                       and creationDate <= 1332088570051    表1中的USERID只能在表2中 
       SQL语句我是写出来了 但执行起来特别慢
      

  3.   


    SELECT A.USER_ID, SUM(A.POINTS)AS POINTS
    FROM REWARD A,  REWARD B
    WHERE A.USER_ID = B.USER_ID
    AND 
    (
        B.reationDate >= 1232088570051
    AND B.creationDate <= 1332088570051
    )
    GROUP BY A.USER_ID