我試圖讓所有的「balcao」與最大。 「nCli」的值與mysql具有和聚合功能
SELECT cli.idBalcao, count(*) AS nCLientes
FROM cliente AS cli
GROUP BY cli.idBalcao
HAVING nClientes=MAX(nClientes)
任何人都知道爲什麼這樣不起作用? 我使用用戶定義的變量解決了這個問題,但是這個代碼應該在MySQL上工作。
我試圖讓所有的「balcao」與最大。 「nCli」的值與mysql具有和聚合功能
SELECT cli.idBalcao, count(*) AS nCLientes
FROM cliente AS cli
GROUP BY cli.idBalcao
HAVING nClientes=MAX(nClientes)
任何人都知道爲什麼這樣不起作用? 我使用用戶定義的變量解決了這個問題,但是這個代碼應該在MySQL上工作。
如果你改變,要
SELECT cli.idBalcao, count(*) AS nCLientes,
MAX(nCli) as maxClientes
FROM cliente AS cli
GROUP BY cli.idBalcao
HAVING nClientes = maxClientes
(OR)
SELECT cli.idBalcao, count(*) AS nCLientes
FROM cliente AS cli
GROUP BY cli.idBalcao
HAVING nClientes IN (select MAX(nCli) from cliente)
見http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an -mcve-for-what-seem-to-the-very-simple-sql-query – Strawberry