Code for Geniuses

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.

  1. ๐Ÿ’ผThe second highest salaryReturn the second highest salary in the employees table (a single row and a single column).Easy
  2. ๐Ÿ›’Customers who never boughtShow the name of the customers who have no orders at all.Easy
  3. ๐Ÿ“งDuplicate emailsShow each email that appears more than once in customers and how many times it appears.Easy
  4. ๐Ÿ…The top earner in each departmentShow the department and the name of the person with the highest salary in each department.PROMedium
  5. ๐Ÿ“…Month-by-month revenueShow each month (in YYYY-MM format) and its total revenue, sorted from the oldest month to the most recent.PROMedium
  6. ๐Ÿฅ‡Each customer's first orderShow the name of each customer with orders and the date of their first order.PROMedium
  7. ๐Ÿ“ˆGrowth versus the previous monthShow each month and the difference between its revenue and the previous month's (empty in the first month).PROHard