TGViewer
Data Analytics Data Analytics @sqlspecialist ยท 111K subscribers
Post #2397 8.22K
๐Ÿง  Top 10 Real-World SQL Scenarios with Sample Answers ๐Ÿ“Š๐Ÿ’ป

1. Find Duplicate Records in a Table
SELECT email, COUNT(*)  
FROM customers
GROUP BY email
HAVING COUNT(*) > 1;


2. Find the Second Highest Salary
SELECT MAX(salary)  
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);


3. Customers with More Than 3 Orders in Last 30 Days
SELECT customer_id  
FROM orders
WHERE order_date >= CURRENT_DATE - INTERVAL '30 days'
GROUP BY customer_id
HAVING COUNT(*) > 3;


4. Calculate Monthly Revenue
SELECT DATE_TRUNC('month', sale_date) AS month,  
SUM(amount) AS monthly_revenue
FROM sales
GROUP BY month
ORDER BY month;


5. Find Employees Without Managers
SELECT *  
FROM employees
WHERE manager_id IS NULL;


6. Join Two Tables and Filter by Amount
SELECT o.order_id, c.name, o.amount  
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE o.amount > 100;


7. Use CASE for Conditional Logic
SELECT name,  
CASE
WHEN score >= 90 THEN 'Excellent'
WHEN score >= 75 THEN 'Good'
ELSE 'Needs Improvement'
END AS rating
FROM students;


8. Find Top-Selling Products
SELECT product_id, SUM(quantity) AS total_sold  
FROM sales
GROUP BY product_id
ORDER BY total_sold DESC
LIMIT 5;


9. Identify Inactive Users
SELECT user_id  
FROM users
WHERE last_login < CURRENT_DATE - INTERVAL '90 days';


๐Ÿ”Ÿ Calculate Conversion Rate
SELECT COUNT(*) FILTER (WHERE status = 'converted') * 100.0 / COUNT(*) AS conversion_rate  
FROM leads;


๐Ÿ’ก Pro Tip: Practice these with real datasets and explain your logic clearly in interviews.

๐Ÿ’ฌ Tap โค๏ธ if this helped you prep smarter!
  • โค 25
  • ๐Ÿ‘ 5
  • ๐Ÿฅฐ 2
  • ๐Ÿ‘ 2
More from @sqlspecialist
  1. Oct 13, 2026๐Ÿ“Š Data Analyst Interview Series โ€” Part 9 Guys, let's continue our Data Analyst Interviewโ€ฆ
  2. Oct 13, 2026๐—ง๐—ข๐—ฃ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ ๐—œ๐—ก ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! Explorโ€ฆ
  3. Oct 12, 20268๏ธโƒฃ You receive a dataset with inconsistent date formats. How would you clean it? Sample Aโ€ฆ
  4. Oct 12, 2026๐Ÿ“Š Data Analyst Interview Series โ€” Part 7 Guys, let's continue our Data Analyst Interviewโ€ฆ
  5. Oct 12, 2026๐Ÿš€ ๐—ช๐—ต๐—ถ๐—ฐ๐—ต ๐—ง๐—ฒ๐—ฐ๐—ต ๐—ฆ๐—ธ๐—ถ๐—น๐—น ๐—ช๐—ถ๐—น๐—น ๐—ฌ๐—ผ๐˜‚ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ถ๐—ป ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ? Want to builโ€ฆ
  6. Oct 9, 2026โ€œHere, the data is sorted by the second column in descending order and the first five rowsโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’