For your next job
SQL interview prep
The problems that come up most often in interviews for data roles. Solve them in a real editor and then compare your query with the explained solution.
- ๐ผThe second highest salaryReturn the second highest salary in the employees table (a single row and a single column).SubqueriesEasy
- ๐Customers who never boughtShow the name of the customers who have no orders at all.LEFT JOINEasy
- ๐งDuplicate emailsShow each email that appears more than once in customers and how many times it appears.GROUP BY ยท HAVINGEasy
- ๐ The top earner in each departmentShow the department and the name of the person with the highest salary in each department.Window functionsPROMedium
- ๐ Month-by-month revenueShow each month (in YYYY-MM format) and its total revenue, sorted from the oldest month to the most recent.Group by datePROMedium
- ๐ฅEach customer's first orderShow the name of each customer with orders and the date of their first order.JOIN ยท MINPROMedium
- ๐Growth versus the previous monthShow each month and the difference between its revenue and the previous month's (empty in the first month).WITH ยท LAGPROHard