我正在学习Postgres并有一个基本问题。
假设我有以下内容:
SELECT "id", count(*) AS "count"
FROM "events" GROUP BY "id" ORDER BY "id"
如何从中检索特定的ID?比如,ID 12345?
答案 0 :(得分:0)
添加having
子句,如
SELECT "id", count(*) AS "count"
FROM "events" GROUP BY "id" having id = 12345 ORDER BY "id"
在此处查看示例
答案 1 :(得分:0)
由于过滤器不在聚合值上,因此不会在WHERE子句中添加它更好(性能方面)?
SELECT "id", count(*) AS "count"
FROM "events" WHERE id = 12345 GROUP BY "id"
也许订单也没有任何用途。