Deviopath › PostgreSQL

Popular Tags

Medium · Arrays

unnest(array) turns an array into rows, one per element. Used in FROM, it gives every book one row per tag. (To test a single value instead, use value = ANY(array).)

Each book has a tags array. Return tag and book_count (how many books carry that tag). Books with no tags add nothing. Sort by book_count descending, then tag ascending.

Next: Above Their Department Average