Databases

PostgreSQL interview questions

Live

Joins, window functions, EXPLAIN, MVCC, indexes and PostgreSQL-specific features.

120 questions · 60 theory · 60 coding

Subtopics

  • Joins10
  • Aggregates & GROUP BY/HAVING10
  • Window functions10
  • CTEs10
  • Indexes & seeks vs scans10
  • Execution plans10
  • Transactions & isolation levels10
  • Deadlocks10
  • Normalization10
  • Stored procedures10
  • NULL semantics10
  • Query tuning10

Sample questions

  • CodingJuniorAggregates & GROUP BY/HAVING

    Table sales(id, region, amount) where amount is nullable. For every region that appears in the table return how many sale rows it has and the total of their amounts, treating a missing amount as 0 so that a region whose sales all have NULL amounts reports 0.00 rather than

  • CodingJuniorAggregates & GROUP BY/HAVING

    Table orders(id, customer_id, total) with total NOT NULL. Find the customers who placed at least three orders and whose average order total is strictly greater than 50. Report the customer id, the number of orders and the average rounded to two decimal places.

  • TheoryJuniorAggregates & GROUP BY/HAVING

    In plain words, what does GROUP BY do to a result set, and what is the difference between COUNT(*) and COUNT(some_column)?

  • TheoryJuniorAggregates & GROUP BY/HAVING

    When would you filter in WHERE and when in HAVING? Can a query use both in the same statement?

  • TheoryJuniorAggregates & GROUP BY/HAVING

    Why does PostgreSQL reject SELECT customer_id, name, SUM(total) FROM orders JOIN customers ... GROUP BY customer_id in some cases and accept it in others? What is going on?

  • CodingJuniorCTEs

    Table orders(id, customer_id, total) with total NOT NULL. Compute how much each customer spent in total, then return only the customers whose total is strictly greater than the average customer total (the average over customers, not over orders).