我正在創建一個聊天,我不想要任何帶有5個以上的報告的消息。報告存儲在table reports
中。SQL語句where子句COUNT()
這是我的SQL:沒有WHERE report_count < 5
SELECT *,
message_id AS current_id,
(SELECT Count(report_id)
FROM reports
WHERE report_messages_fk = current_id) AS report_count
FROM messages
INNER JOIN users
ON message_user_fk = users.id
WHERE report_count < 5
ORDER BY message_date ASC
LIMIT 100
這個SQL工作,但沒有用它。
任何幫助表示讚賞。
編輯:與更換WHERE
條款和HAVING clause fixed the issue, thanks.
什麼是它的投擲錯誤的具體信息?錯誤號碼? – asdf
你不能在'where'子句中使用列別名。使用'having'子句insetad。 –
這是錯誤代碼:#1054 –