如何选择计数> 0?
的所有行"其中hits> 0"不起作用。
SELECT b . * , COUNT( a.abfrage_id ) AS `hits`
FROM abfragen_ergebnisse a
RIGHT JOIN suchen b ON a.abfrage_id = b.id
WHERE b.id <140
GROUP BY b.id
ORDER BY `hits` DESC , b.`id` ASC
答案 0 :(得分:1)
您应该使用HAVING
:
SELECT b . * , COUNT( a.abfrage_id ) AS `hits`
FROM abfragen_ergebnisse a
RIGHT JOIN suchen b ON a.abfrage_id = b.id
WHERE b.id <140
GROUP BY b.id
HAVING `hits` > 0
ORDER BY `hits` DESC , b.`id` ASC