+----------+---------------------+-------+
| ID | date_value | value |
+----------+---------------------+-------+
| 1 | 2011-04-20 21:03:05 | 150 |
| 1 | 2011-04-20 21:03:04 | 150 |
| 2 | 2011-04-20 21:03:03 | 20 |
| 2 | 2011-04-20 21:02:09 | 130 |
| 2 | 2011-04-20 21:02:08 | 130 |
| 3 | 2011-04-20 21:02:07 | 20 |
| ... | ... | ... |
+----------+---------------------+-------+
使用此表,如何使用select来查找超过100的值超过2的ID?
答案 0 :(得分:5)
SELECT ID, count(*) from mytable
WHERE value > 100
GROUP BY ID
HAVING count(*) >2
答案 1 :(得分:0)
您可以执行以下操作
select id,count(value)
from table1
where value > 100
having count(value) > 2
group by ID;
答案 2 :(得分:0)
您可以使用此SQL语句:
SELECT id, count(1)
FROM mytable
WHERE value > 100
GROUP BY id
HAVING count(1) > 2;