1
SELECT ip, COUNT(ip) as count FROM gnb_full_log GROUP BY ip

这将返回带有 ip 和 count 列的表。我想选择 count = 1 OR 1 < count < 6 的记录

4

3 回答 3

3

使用HAVING子句:

SELECT   ip, COUNT(*) as count
FROM     gnb_full_log
GROUP BY ip
HAVING   count = 1

或者

SELECT   ip, COUNT(*) as count
FROM     gnb_full_log
GROUP BY ip
HAVING   1 < count AND count < 6
于 2013-07-22T16:22:40.457 回答
3

尝试这个:

SELECT ip, COUNT(ip) as count 
FROM gnb_full_log GROUP BY ip
HAVING COUNT(ip) >= 1 and COUNT(ip) < 6

HAVING 子句在聚合函数上是 WHERE

于 2013-07-22T16:22:51.807 回答
1

用这个:-

SELECT ip, COUNT(ip) as count FROM gnb_full_log GROUP BY ip HAVING  count > 1 AND count < 6
于 2013-07-22T16:23:22.900 回答