easy
Second Highest Salary Write a SQL query to find the second highest salary from the `employees` table. If there is no second highest, return NULL.
#subquery #window-functions
medium
Top 3 Earners per Department For each department, find the top 3 highest-paid employees. Return department, employee name, and salary ordered by department and salary descending.
#window-functions #partitioning
medium
Running Total of Revenue Calculate the running total of daily revenue ordered by date. Return date, daily_revenue, and running_total.
#window-functions #aggregation
hard
Find Gaps in Log Sequence Given a table of sequential log IDs, find all the missing IDs (gaps) in the sequence. Return start_gap and end_gap for each range of missing IDs.
#window-functions #CTE #gaps-and-islands
hard
Pivot Monthly Sales Transform rows of monthly sales data into columns. Output: product_name, jan_sales, feb_sales, mar_sales using conditional aggregation.
#pivot #conditional-aggregation
hard
Users with 3+ Consecutive Login Days Find all users who logged in for 3 or more consecutive days. Return user_id and the length of their longest login streak.
#gaps-and-islands #window-functions #date-math