~/ learn/ postgresql/ cards/ HAVING: filtering groups
1 of 2

Show each genre and its book count, but only for genres with at least 2 books.

Show each genre and its book count, but only for genres with at least 2 books.

Answer

SELECT genre, COUNT(*) AS books FROM books GROUP BY genre HAVING COUNT(*) >= 2;

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4475ec21-caf0-4332-98d2-9ce971aac276/flashcard utf-8 LF