此查詢的工作:過濾上的值使用子查詢計算
select r.id, name, description, private, auth,
(select count (*) from message m where m.room = r.id) as messageCount
from room r left join room_auth a on a.room=r.id and a.player='11'
where private is false or auth is not null;
這一個不:
select r.id, name, description, private, auth,
(select count (*) from message m where m.room = r.id) as messageCount
from room r left join room_auth a on a.room=r.id and a.player='11'
where private is false or auth is not null or messageCount>1000;
我得到這個錯誤:
ERREUR: the « messageCount » column doesn't exit
我怎樣才能乾淨有效地添加條件messageCount
?或者更一般地說,如何達到預期的結果(由於room
表和聯接中的列數,對於直接查詢message
表和room
的組的查詢,我沒有真正的興趣)?
工作,+1,但...這是如此醜陋... –