select sum(points) as total_points from soMetable where total_points > 25 group by username
我无法在where子句中引用total_points,因为我收到以下错误:ERROR:列“total_points”不存在.在这种情况下,我在where子句中没有重写sum(points)的问题,但是我想要一些做上面所说的方法.
>有没有办法将结果存储在变量中而不使用存储过程?>如果我在where子句中重写sum(points),postgres是否足够聪明才能重新计算?
SELECT t.* FROM ( SELECT SUM(points) AS total_points FROM soMetable GROUP BY username ) t WHERE total_points > 25
编辑:忘记别名子查询.