,是它在SELECT列表可能重新WHERE子句中的子查詢,像這樣:如何使用相同的子查詢的SELECT和WHERE性能目的條款
SELECT p.id, nItens FROM purchase AS p
WHERE ((SELECT COUNT(*) AS n FROM itens WHERE purchase_id=p.id) AS nItens) > 1
避免:
SELECT p.id, (SELECT COUNT(*) AS n FROM itens WHERE purchase_id=p.id) AS nItens
FROM purchase AS p
WHERE (SELECT COUNT(*) AS n FROM itens WHERE purchase_id=p.id) > 1
是的,我試着問之前,並得到這個錯誤:未知列'nItens'在'where子句' –
之前你問你把'AS nItens'放在Where子句而不是選擇 –
不是,這是爲了解決這個問題。你測試了你的解決方案嗎? –