PostgreSQL 从哪里的总和中检查值

PostgreSQL check value from sum in where

我正在尝试将 done 值添加到 where 子句,因此我只能显示已完成的待办事项的结果,但不断收到错误消息:

select "todo", SUM( "test"."count" ) as "done"
from B 
Where "done" =  "todo"

这是错误:

q_driver: [PGRES_FATAL_ERROR]ERRORE: the column "done" don't exist

但是如果我删除 where 子句就会显示该列

您不能在同一个 select 查询 where 子句中使用 alias 名称

select * from
(
select "todo", SUM( "test"."count" ) as "done"
from B 
GROUP BY "todo"
)
Where "done" =  "todo"