简体   繁体   中英

MySql inner join COUNT>0

How can i select all the rows with a count>0 ?

"where hits>0" does not work.

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 

You should use 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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM