Databases & SQL practice questions
10 questions in 1 test. Open one to answer it on its own, or take a whole test.
Test 1
Take Test 1 ›- A report must list every customer, with the id of their paid order if they have one and NULL otherwise. The data is: customers(id, name): (1, 'Ana'), (2, 'Ben'), (3, 'Cai')… · Joins
- The table employees(name, dept, emp_type, salary) holds both full-time and part-time staff. HR wants the departments whose average full-time salary is above 60000. Part-time… · Aggregation & Grouping
- The table employees(id, manager_id) contains five rows: (1, NULL), (2, 1), (3, 1), (4, NULL), (5, 2). A developer runs these two queries. What numbers do they return, in order?… · NULL Semantics
- A developer wants each customer's total spend and runs this query on PostgreSQL: SELECT customer_id, order_date, SUM(amount) FROM orders GROUP BY customer_id; It fails with… · Aggregation & Grouping
- An application has a customers table with primary key id, and an orders table with a customer_id column. A customer can place many orders. A bug recently inserted orders whose… · Keys & Constraints
- A table is defined as employees(emp_id PRIMARY KEY, emp_name, dept_id, dept_name). Every employee in a department repeats the same dept_name. When the "Ops" department was… · Schema Design & Normalization
- Transaction T1 runs at READ COMMITTED and executes SELECT COUNT(*) FROM orders WHERE status = 'pending';, which returns 12. While T1 is still open, transaction T2 inserts a new… · Transactions & Isolation
- A PostgreSQL table customers has 20 million rows and a B-tree index on email. Statistics are up to date. EXPLAIN shows that SELECT * FROM customers WHERE email LIKE 'alice%'… · Indexes & Performance
- The table scores(name, score) contains: ('Ana', 90), ('Ben', 85), ('Cai', 90), ('Dev', 80). SELECT name, score, ROW_NUMBER() OVER (ORDER BY score DESC) AS rn, RANK() OVER (ORDER… · Window Functions
- A team is building a wallet service. A transfer debits one account and credits another. If the server crashes between those two steps, the system must never be left with only one… · Transactions & Isolation