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

bgym start sql-querying brings up a pinned Postgres 16 container and seeds a small International Booker Prize longlist. Nothing is installed on your machine. Read seed/ to see the tables and edge cases, then write each answer in reps/NN/answer.sql; bgym run NN pipes that file into psql and prints the rows. bgym reset removes the database volume and seeds it again.

You need enough SQL to select rows and recognise a primary key and foreign key. The statements assume the course vocabulary around filters, joins, subqueries, set operations and aggregates. Find the syntax as each trap asks for it.

The data has books, authors, translators, publishers and ratings. It is deliberately imperfect: 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 has trailing whitespace. Those are data conditions, not hints about the query.

This is the first SQL set, so nothing comes before it. Finish here before sql-designing-and-writing.

Reps

In order — each one assumes the ones before it. Open a rep to read it.

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