𝗜𝗻𝘁𝗲𝗿𝘃𝗶𝗲𝘄𝗲𝗿:
You have 2 minutes to solve this SQL query.
Find employees whose salary is higher than the average salary of all other departments (excluding their own department).
Assume the table structure:
employees(employee_id, employee_name, department, salary)
𝗠𝗲: Challenge accepted! 💪
SELECT
employee_id,
employee_name,
department,
salary
FROM employees e1
WHERE salary > (
SELECT AVG(salary)
FROM employees e2
WHERE e2.department <> e1.department
);
💡 Explanation:
This query compares each employee's salary against the average salary of all employees outside their own department.
• The outer query processes each employee.
• The correlated subquery calculates the average salary of employees in all other departments.
• Employees whose salary exceeds that average are returned.
This question tests your understanding of:
✅ Correlated Subqueries
✅ Aggregate Functions (AVG)
✅ Conditional Filtering
✅ Cross-group Comparisons
🎯 Expected Output Example
Employee: John | Department: IT | Salary: 95,000
Employee: Sarah | Department: HR | Salary: 82,000
🚀 Alternative Using Common Table Expressions (CTEs)
WITH dept_avg AS (
SELECT
department,
AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT
e.employee_id,
e.employee_name,
e.department,
e.salary
FROM employees e
WHERE e.salary > (
SELECT AVG(avg_salary)
FROM dept_avg d
WHERE d.department <> e.department
);
This version first computes department-level averages and then compares each employee's salary with the average of the other departments' averages.
🚀 Tip for SQL Job Seekers:
Interviewers often ask questions that compare data within a group versus outside a group. These problems test your understanding of correlated subqueries and aggregate calculations across multiple levels.
❤️ React with ❤️ for more SQL interview challenges!
Data Analysis Books | Python | SQL | Excel | Artificial Intelligence | Power BI | Tableau | AI Resources
@learndataanalysis · 53.3K subscribers
TechCreated in 2022
Data Analysis Useful Resources #dataanalysis #dataanalysisbooks #sqlbooks #pythonbooks #tableau #powerbi #datavisualization For promotions: @coderfun
Information
Username@learndataanalysis
CreatedOctober 23, 2022
Channel history
Channel created October 23, 2022per Telegram
We have been tracking it since July 17, 2026
In all that time the channel has changed neither its name, nor its @username, nor its avatar.
We show only what we have seen ourselves.
These numbers aren’t from todayLast measured on September 30, 2026. The source has been silent since, so this is the last thing we saw — not the channel’s current state.
⌘K
Newest first
Share channel “Data Analysis Books | Python | SQL | Excel | Artificial Intelligence | Power BI | Tableau | AI Resources”
The short link opens the channel straight in the Telegram app — not in a browser tab.
tg.me/go/learndataanalysisIs this your channel? Add @tgme as admin — and see how many people click your links. Get the stats →




