0

以下是我的代码

SELECT b.fulldate, 
       b.userid, 
       Count(a.isclanmatch) 
FROM  (SELECT fulldate, 
              realmatchid, 
              isclanmatch 
       FROM   gro_int.int_match 
       WHERE  ( fulldate BETWEEN '2013-06-30' AND Now() - 2 ) 
              AND isclanmatch = 1 
       GROUP  BY realmatchid)a 
      INNER JOIN gro_int.int_match_user b 
              ON b.realmatchid = a.realmatchid 
WHERE  ( b.fulldate BETWEEN '2013-06-30' AND Now() - 2 ) 
GROUP  BY userid 

fulldate    userid  count(a.isclanmatch)
2013-07-09  1417    4
2013-07-15  1581    2
2013-06-30  1603    1

我想要做的是只显示 a.isclanmatch >=2 的计数。可能吗?

4

3 回答 3

3

添加

HAVING COUNT(a.isclanmatch)>=2

到您的查询结束

于 2013-07-29T08:43:34.847 回答
2

我想你想做:

HAVING COUNT(a.isclanmatch)>=2
于 2013-07-29T08:46:18.873 回答
-1

假设您当前的查询很好,这应该可以

WITH mycte as(
SELECT b.fulldate, b.userid, COUNT(a.isclanmatch) colname
FROM(
    SELECT fulldate, realmatchid, isclanmatch
    FROM gro_int.int_match
    WHERE (fulldate BETWEEN '2013-06-30' AND NOW()-2) AND isclanmatch = 1
    GROUP BY realmatchid)a
        INNER JOIN gro_int.int_match_user b
    ON b.realmatchid = a.realmatchid
    WHERE (b.fulldate BETWEEN '2013-06-30' AND NOW()-2)
GROUP BY userid
)
select * from mycte where colname >= 2
于 2013-07-29T09:10:07.503 回答