在Postgres列中返回特定ID

时间:2013-12-29 22:39:12

标签: postgresql

我正在学习Postgres并有一个基本问题。

假设我有以下内容:

SELECT "id", count(*) AS "count"
            FROM "events" GROUP BY "id" ORDER BY "id"

如何从中检索特定的ID?比如,ID 12345?

2 个答案:

答案 0 :(得分:0)

添加having子句,如

SELECT "id", count(*) AS "count"
            FROM "events" GROUP BY "id" having id = 12345 ORDER BY "id"

在此处查看示例

http://sqlfiddle.com/#!15/09fc9/2

答案 1 :(得分:0)

由于过滤器不在聚合值上,因此不会在WHERE子句中添加它更好(性能方面)?

SELECT "id", count(*) AS "count"
            FROM "events" WHERE id = 12345 GROUP BY "id" 

也许订单也没有任何用途。