Curated ANSI SQL practice challenges across Window Functions, CTEs, complex Joins, and aggregations.
| STATUS | # | TITLE & TOPIC TAGS | CATEGORY | DIFFICULTY | ACTION |
|---|---|---|---|---|---|
| 01 | Select Product Name and Price from Inventory#SELECT#Projection | Basic Queries | Easy | ||
| 02 | Find Customer Orders Exceeding 500 Dollars#WHERE#Filtering | Filtering & Sorting | Easy | ||
| 03 | Find All Unique Customer Cities#DISTINCT#Deduplication | Filtering & Sorting | Easy | ||
| 04 | Sort Employees by Salary and Name#ORDER BY#Sorting | Filtering & Sorting | Easy | ||
| 05 | Find the Single Most Expensive Product#LIMIT#Top N | Filtering & Sorting | Easy | ||
| 06 | Find Employees with Salary Between 80,000 and 90,000#BETWEEN#Range Filter | Filtering & Sorting | Easy | ||
| 07 | Find Employees in HR, IT, or Engineering Departments#IN#Set Membership | Filtering & Sorting | Easy | ||
| 08 | Find Employees Whose Names Start with 'A'#LIKE#Wildcards | String Manipulation | Easy | ||
| 09 | Find Employees Without an Assigned Department#IS NULL#Null Handling | Data Quality | Easy | ||
| 10 | Count Total Number of Employees#COUNT#Aggregation | Aggregation & Grouping | Easy | ||
| 11 | Calculate Total Salary Payroll of All Employees#SUM#Aggregation | Aggregation & Grouping | Easy | ||
| 12 | Calculate Company-Wide Average Employee Salary#AVG#Mean Calculation | Aggregation & Grouping | Easy | ||
| 13 | Find Minimum and Maximum Employee Salaries#MIN#MAX | Aggregation & Grouping | Easy | ||
| 14 | Categorize Employees into Compensation Tiers#CASE#Salary Tier | Conditional Logic | Easy | ||
| 15 | Format Employee Name and Department into Single Label#CONCAT#Formatting | String Manipulation | Easy | ||
| 16 | Extract First Three Characters of Employee Name#SUBSTRING#Extraction | String Manipulation | Easy | ||
| 17 | Find Employees with Names Longer than Four Characters#LENGTH#Validation | String Manipulation | Easy | ||
| 18 | Format Employee Names to Uppercase and Departments to Lowercase#UPPER#LOWER | String Manipulation | Easy | ||
| 19 | Round Employee Salaries to One Decimal Place#ROUND#Precision | Numeric & Math | Easy | ||
| 20 | Select Order ID and Date Sorted by Order Date#STRFTIME#Date Formatting | Date & Time | Easy | ||
| 21 | Count Total Employees in Each Department#GROUP BY#Headcount | Aggregation & Grouping | Easy | ||
| 22 | Find Departments with More Than One Employee#HAVING#Threshold Filter | Aggregation & Grouping | Easy | ||
| 23 | Select Employee Names with Column Alias employee_name#AS#Aliasing | Basic Queries | Easy | ||
| 24 | Replace Missing Employee Departments with 'Unassigned'#COALESCE#Default Values | Data Quality | Easy | ||
| 25 | Retrieve Employee Names Along with Department Names#JOIN#Relational Mapping | Joins & Set Operations | Easy | ||
| 26 | Inner Join Employees and Departments to Report Salaries#INNER JOIN#Relational | Joins & Set Operations | Medium | ||
| 27 | Find Customers Who Have Never Placed an Order#LEFT JOIN#Anti-Join | Joins & Set Operations | Medium | ||
| 28 | List All Departments and Matching Employees Using Left Join#LEFT JOIN#Department Roster | Joins & Set Operations | Medium | ||
| 29 | Find Each Employee and Their Direct Manager Name#SELF JOIN#Manager Hierarchy | Joins & Set Operations | Medium | ||
| 30 | Generate Cartesian Cross Product of Employees and Departments#CROSS JOIN#Cartesian Product | Joins & Set Operations | Medium | ||
| 31 | Combine Distinct Names from Employees and Contractors#UNION#Set Union | Joins & Set Operations | Medium | ||
| 32 | Combine All Names from Employees and Contractors Including Duplicates#UNION ALL#Full Union | Joins & Set Operations | Medium | ||
| 33 | Find Employees Earning Higher Than Average Company Salary#Subquery#AVG Filter | Subqueries & CTEs | Medium | ||
| 34 | Find Customers with At Least One Order Using EXISTS#EXISTS#Semi-Join | Subqueries & CTEs | Medium | ||
| 35 | Find Customers with No Orders Using NOT EXISTS#NOT EXISTS#Anti-Join | Subqueries & CTEs | Medium | ||
| 36 | Find High Earners and Their Departments Using Common Table Expression#CTE#WITH Clause | Subqueries & CTEs | Medium | ||
| 37 | Assign Row Numbers to Employees by Salary within Department#ROW_NUMBER#Ordering | Window Functions | Medium | ||
| 38 | Rank Employees by Salary within Department Using RANK#RANK#Ties with Gaps | Window Functions | Medium | ||
| 39 | Rank Employees by Salary within Department Without Gaps Using DENSE_RANK#DENSE_RANK#Dense Ranking | Window Functions | Medium | ||
| 40 | Compare Employee Salary with Preceding Colleague Using LAG#LAG#Preceding Value | Window Functions | Medium | ||
| 41 | Compare Employee Salary with Subsequent Colleague Using LEAD#LEAD#Following Value | Window Functions | Medium | ||
| 42 | Calculate Running Total of Sales Ordered by Date#SUM OVER#Running Total | Window Functions | Medium | ||
| 43 | Find Top 2 Highest Paid Employees in Each Department#ROW_NUMBER#Top N | Window Functions | Medium | ||
| 44 | Find Duplicate User Emails in Accounts Table#HAVING#Duplicate Detection | Data Quality | Medium | ||
| 45 | Deduplicate User Records by Email and Name#DISTINCT#Deduplication | Data Quality | Medium | ||
| 46 | Calculate Total Spend per Customer from Orders#SUM#Customer LTV | Business Analytics | Medium | ||
| 47 | Aggregate Total Sales Revenue by Month#STRFTIME#Monthly Revenue | Time-Series & Analytics | Medium | ||
| 48 | Extract Category Attribute from JSON Logs#JSON#json_extract | String Manipulation | Medium | ||
| 49 | Pivot Department Sales by Year 2023 and 2024#Conditional SUM#Pivoting | Business Analytics | Medium | ||
| 50 | Reconcile Two Tables Using Full Outer Join#FULL OUTER JOIN#COALESCE | Joins & Set Operations | Medium | ||
| 51 | Find Highest-Paid Employee in Each Department#MAX#Department Top Earner | Subqueries & CTEs | Hard | ||
| 52 | Top 3 Highest-Paid Employees per Department#DENSE_RANK#Top 3 per Group | Window Functions | Hard | ||
| 53 | Identify Session Start Boundaries from Clickstream Events#LAG#Sessionization | Window Functions | Hard | ||
| 54 | Find Contiguous Active User Login Streaks#Gaps & Islands#Streak Detection | Gaps & Islands | Hard | ||
| 55 | Lookup Slowly Changing Company Dimension by Effective Date#SCD Type 2#Point-in-Time | Data Warehousing | Hard | ||
| 56 | Filter Incremental Records Past Watermark Timestamp#Watermark#Incremental Load | Data Engineering | Hard | ||
| 57 | Identify Employee Records Failing Quality Check Rules#Data Quality#Validation | Data Quality | Hard | ||
| 58 | Group User Signups into Monthly Acquisition Cohorts#Cohorts#STRFTIME | Time-Series & Analytics | Hard | ||
| 59 | Calculate Sales Performance Metrics by Geographic Region#KPIs#Aggregates | Business Analytics | Hard | ||
| 60 | Standardize and Clean Raw Staging User Records#TRIM#UPPER#Data Cleansing | Data Engineering | Hard | ||
| 61 | Second-Highest Salary in Each Department#DENSE_RANK#Runner-Up#Window Functions | Window Functions | Medium | ||
| 62 | Employees Earning Above Department Average#AVG#Subquery#Benchmark | Subqueries & Joins | Medium | ||
| 63 | Employees Out-Earning Their Direct Supervisors#SELF JOIN#Manager Hierarchy | Self Joins | Medium | ||
| 64 | Third-Highest Company Salary Without Paging#DENSE_RANK#DISTINCT#No Limit | Window Functions | Medium | ||
| 65 | Top 10 Percent Highest Earners per Department#CUME_DIST#Top Decile#Percentiles | Window Functions | Hard | ||
| 66 | Quartile Salary Distribution by Department#NTILE#Quartiles#Bucketing | Window Functions | Medium | ||
| 67 | Employee with Salary Closest to Department Average#AVG#ABS Difference#Window Functions | Window Functions | Hard | ||
| 68 | Employees Out-Earning at Least Three Department Peers#Correlated Subquery#COUNT#Filtering | Correlated Subqueries | Hard | ||
| 69 | Keep Most Recent Customer Record by Timestamp#ROW_NUMBER#Latest Timestamp#Deduplication | Deduplication | Medium | ||
| 70 | Identify Duplicate Customer Profiles on Composite Key#Composite Key#ROW_NUMBER#Deduplication | Deduplication | Medium | ||
| 71 | Audit Customer Email Changes Over Time#LAG#History Tracking#Audit Log | Window Functions | Medium | ||
| 72 | Extract Latest Customer Status from History#ROW_NUMBER#Status History#Latest State | Deduplication | Medium | ||
| 73 | Detect Account Reactivations from Closed to Active#State Transitions#Reactivation#HAVING | Window Functions | Hard | ||
| 74 | Find First and Most Recent Record per Customer#MIN_BY#MAX_BY#Lifecycle Snapshot | Aggregation & Grouping | Medium | ||
| 75 | Filter Duplicate Records Retaining Minimum ID#Self Join#Min ID Retention#Deduplication | Deduplication | Medium | ||
| 76 | Detect Conflicting Status Changes on Same Date#GROUP BY#HAVING#Audit Log | Data Quality | Medium | ||
| 77 | Find Managers with More Than Five Direct Reports#GROUP BY#HAVING#Hierarchy | Aggregation & Joins | Medium | ||
| 78 | Detect Salary Ties Within the Same Department#EXISTS#Salary Ties#Subqueries | Correlated Subqueries | Medium | ||
| 79 | Customers Who Purchased Product A but Never Product B#NOT EXISTS#Market Basket#Set Difference | Set Operations & Joins | Medium | ||
| 80 | Customers Who Bought Every Product in a Category#Relational Division#HAVING#COUNT DISTINCT | Relational Division | Hard | ||
| 81 | Products Purchased by 80 Percent of Active Customers#CTE#Market Penetration#Ratio Analysis | Business Analytics | Hard | ||
| 82 | Identify Active Customers Ordering Every Month of the Year#DATE_TRUNC#12-Month Coverage#Customer Loyalty | Time-Series | Medium | ||
| 83 | High-Value Customers Spending Above Global Average#LTV#CTE#Above Average | Business Analytics | Medium | ||
| 84 | Departments with Average Salary Exceeding Company Average#HAVING#AVG#Benchmark | Aggregation & Subqueries | Medium | ||
| 85 | Find Users with 3 Consecutive Days Login Streak#Gaps & Islands#Login Streaks#Window Functions | Gaps & Islands | Hard | ||
| 86 | Longest Consecutive Daily Login Streak per User#Gaps & Islands#MAX Streak#Window Functions | Gaps & Islands | Hard | ||
| 87 | Customers with Consecutive 3-Month Purchasing Cadence#Gaps & Islands#Cadence#Month Math | Time-Series | Hard | ||
| 88 | Calculate Days Elapsed Between First and Second Purchase#Repeat Purchase#Date Difference#ROW_NUMBER | Time-Series | Medium | ||
| 89 | Calculate Month-over-Month (MoM) Revenue Growth Rate#LAG#MoM Growth#Percentage Change | Financial Analytics | Medium | ||
| 90 | Compute 7-Day Trailing Rolling Average Revenue#Rolling Average#RANGE BETWEEN#Window Functions | Time-Series | Hard | ||
| 91 | Calculate 30-Day Trailing Rolling Spend per Customer#Rolling Sum#RANGE BETWEEN#Customer Spend | Time-Series | Hard | ||
| 92 | Customers Making Repeat Purchase Within 30 Days#Repeat Conversion#Date Math#Window Functions | Time-Series | Medium | ||
| 93 | Identify Inactive Transaction Periods Exceeding 30 Days#LEAD#Dormancy Gaps#Customer Inactivity | Gaps & Islands | Medium | ||
| 94 | Detect Employees Absent for 3 or More Consecutive Days#Gaps & Islands#Attendance#Absence Tracking | Gaps & Islands | Hard | ||
| 95 | Continuous Periods of High-Volume Daily Sales Exceeding 100K#Gaps & Islands#Sales Waves#Revenue Spikes | Gaps & Islands | Hard | ||
| 96 | Customer Activity Span: First Date, Last Date, and Active Days#MIN/MAX#COUNT DISTINCT#Customer Lifecycle | Aggregation & Grouping | Easy | ||
| 97 | Top 3 Products by Revenue for Each Month#DENSE_RANK#Monthly Top Products#E-commerce | Business Analytics | Hard | ||
| 98 | Top 2 Customers by Revenue for Each Month#DENSE_RANK#Top Spenders#Monthly Customers | Business Analytics | Medium | ||
| 99 | Customers with Increasing Monthly Spending for 3 Consecutive Months#Gaps & Islands#Spending Growth#Monthly Trends | Time-Series | Hard | ||
| 100 | Identify Immediately Churned Customers from Last Month#NOT EXISTS#Churn Analysis#Cohort Inactivity | Customer Analytics | Medium | ||
| 101 | Identify Users with 7-Day Continuous Login Streak#Gaps & Islands#7-Day Streak#Window Functions | Gaps & Islands | Hard | ||
| 102 | Calculate Year-over-Year (YoY) Revenue Growth Rate#YoY Growth#EXTRACT#LAG | Financial Analytics | Medium | ||
| 103 | Identify Continuous Active Periods for Each User#Gaps & Islands#User Activity#Streak Detection | Gaps & Islands | Hard | ||
| 104 | Measure Customer Retention at Day-1, Day-7, and Day-30#Cohort Retention#CROSS JOIN#Retention Curves | Cohort Analytics | Hard | ||
| 105 | Calculate Monthly Customer Repeat Rate Percentage#Repeat Rate#LAG#Customer Retention | SaaS Metrics | Hard | ||
| 106 | Top 10 Customers Revenue Concentration Share#Revenue Share#Pareto Analysis#Window Functions | Executive Analytics | Medium |