backendgym backendgym · reps Sign in with GitHubSign in
← Reps
PostgreSQL Warm-up

SQL · Querying

Read a schema you did not write and get the rows out of it: filters, joins, subqueries, sets and aggregates, with the NULLs and orphans that bite.

sql-querying / README.md

A small International Booker Prize longlist in PostgreSQL 16: books, their authors and translators, publishers and ratings. Each rep is one question the data can answer. You write the query, run it with psql, and compare the rows with the expected result printed in the statement.

You work in a copy of the set's starter, a repository of your own. Setting up the database is its first task: bring up a Postgres, load seed/ into it, and check the counts its README gives. How you run Postgres is your call.

You should already be able to select rows and tell a primary key from a foreign key. The reps use the usual vocabulary (filters, joins, subqueries, set operations, aggregates), and you look up the syntax when a rep needs it.

Read seed/ before the first rep. The data is messy on purpose. Translator IDs and ratings can be NULL, one author has no book, one book has no author, two publisher records share a name, and one publisher name ends in a space. That's what the data is like; it doesn't tell you what to write.

This is the first SQL set. sql-designing-and-writing comes after it.

Reps

Do them in order. Each rep assumes the ones before it.

  1. 01 Filter the longlist
  2. 02 Find missing translators
  3. 03 Count publisher records
  4. 04 Average each book
  5. 05 Find translated books
  6. 06 Keep the orphan author
  7. 07 Compare title sets
  8. 08 Group authors with books
  9. 09 Preserve both sides