TGTGInsighttelegram intelligenceLIVE / telegram public index
← Data Analytics
Data Analytics avatar

TGINSIGHT POST

Post #2401

@sqlspecialist

Data Analytics

Views9,350Post view count
PostedOct 1510/15/2025, 02:40 PM
Post content

Post content

🧠 Real-World SQL Scenario-Based Questions & Answers 1. Get the 2nd highest salary from the Employees table SELECT MAX(salary) AS SecondHighest FROM Employees WHERE salary < (SELECT MAX(salary) FROM Employees); 2. Find employees without assigned managers SELECT * FROM Employees WHERE manager_id IS NULL; 3. Retrieve departments with more than 5 employees SELECT department_id, COUNT(*) AS employee_count FROM Employees GROUP BY department_id HAVING COUNT(*) > 5; 4. List customers who made no orders SELECT c.name FROM Customers c LEFT JOIN Orders o ON c.id = o.customer_id WHERE o.id IS NULL; 5. Find the top 3 highest-paid employees SELECT * FROM Employees ORDER BY salary DESC LIMIT 3; 6. Display total sales for each product SELECT product, SUM(amount) AS total_sales FROM Sales GROUP BY product; 7. Get employee names starting with 'A' and ending with 'n' SELECT name FROM Employees WHERE name LIKE 'A%n'; 8. Show employees who joined in the last 30 days SELECT * FROM Employees WHERE join_date >= CURRENT_DATE - INTERVAL 30 DAY; 💬Tap ❤️ for more!