SQL子查询从返回的结果中选择

时间:2013-07-22 16:21:07

标签: mysql

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

这将返回包含ip和count列的表。我想选择count = 1 OR 1<计数< 6

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:3)

试试这个:

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

HAVING子句是聚合函数的WHERE

答案 2 :(得分:1)

使用: -

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