Mysql
 sql >> Datenbank >  >> RDS >> Mysql

MySQL:SELECT und COUNT in derselben Abfrage

Etwa so:-

SELECT city.id, city.name, city.slug, COUNT(club.id) AS club_count
FROM city
INNER JOIN club
ON city.id = club.city_id
WHERE club.published = 1
GROUP BY city.id, city.name, city.slug
HAVING club_count > 0