Interview Q&A / PostgreSQL
PostgreSQL interview questions
Indexes, EXPLAIN, transactions and isolation, JSONB and the Postgres specifics backend interviews probe.
Prefer rapid revision? Practise PostgreSQL short interview answers →
- How do you compute a running total, and what is a window frame?
Use sum(x) OVER (ORDER BY ...). The frame decides which rows around the current one are included; with ORDER BY the default is from the start up to the current row (including peers with equal values), which gives a running total.
IntermediateQuick answer1 min read - How do you get the top 2 highest-paid employees in each department?
Number the rows within each department using ROW_NUMBER or DENSE_RANK with PARTITION BY dept ORDER BY salary DESC, then filter on that number in an outer query. A lateral join is an alternative.
IntermediateQuick answer1 min read