Sunday, May 31, 2026

Top SQL Queries for Practice (With Short Answers) - Real-Time Scenario Queries (81–100)

 

  1. Find duplicate transactions
    Use GROUP BY transaction_id HAVING COUNT(*) > 1.
  2. Find inactive customers
    Find customers with no orders in last 6 months.
  3. Find repeat customers
    Group by customer and filter COUNT(order_id) > 1.
  4. Find one-time customers
    Group by customer and filter COUNT(order_id) = 1.
  5. Find top-selling products
    Group by product and order by total quantity sold desc.
  6. Find least-selling products
    Group by product and order by total quantity sold asc.
  7. Find average order value
    SUM(order_amount) / COUNT(order_id).
  8. Find monthly revenue
    Group by month and sum order amount.
  9. Find YoY sales growth
    Compare current year sales with previous year sales.
  10. Find MoM sales growth
    Use LAG() on monthly sales.
  11. Find customer lifetime value
    Sum total purchase amount by customer.
  12. Find customer churn
    Find customers with no recent activity.
  13. Find best performing region
    Group by region and sort by sales desc.
  14. Find worst performing region
    Group by region and sort by sales asc.
  15. Find null-heavy columns
    Use COUNT(*) - COUNT(column).
  16. Find bad quality records
    Check NULLs, duplicates, invalid formats.
  17. Find orphan records
    Use LEFT JOIN and filter unmatched child records.
  18. Validate source vs target count
    Compare COUNT(*) from both tables.
  19. Find changed records in ETL
    Compare source and target using hash/timestamp.
  20. Find load failures in ETL
    Check audit table, rejected rows, and error logs.