当Oracle SQL具有不同的值时,它会获取id

时间:2014-11-18 10:27:58

标签: sql oracle

+----------+---------------------+-------+
| 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?

3 个答案:

答案 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;