我有一个这样的 MySQL 查询:
SELECT *, SUM(...some SQL removed for brevety) AS Occurrences FROM some_table AS q
WHERE criterion="value" GROUP BY q.P_id ORDER BY Occurrences DESC LIMIT 10;
我想将结果限制为 Occurrences>0 的行。这对我来说似乎很简单,但我似乎无法让它发挥作用。无论我尝试什么,WHERE 或 HAVING,每当我尝试添加此限制时,我都会得到 NO ROWS 作为回报。我很肯定我的表中有应该返回的数据。有谁知道如何完成我正在做的事情?
我试过这个,但它仍然不起作用。任何想法为什么它仍然不起作用?
SELECT *, SUM(...some SQL removed for brevety) AS Occurrences FROM some_table AS q
WHERE criterion="value" HAVING SUM(...some SQL removed for brevety)>0 GROUP BY q.P_id ORDER BY Occurrences DESC LIMIT 10;