MySql内连接COUNT> 0

时间:2015-11-09 15:39:34

标签: mysql sorting count inner-join

如何选择计数> 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 

1 个答案:

答案 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