Data Analytics
111K subscribers
225 photos
1 video
2 files
952 links
Perfect channel to learn Data Analytics

Learn SQL, Python, Alteryx, Tableau, Power BI and many more

For Promotions: @coderfun @love_data
Download Telegram
๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐Ÿญ๐Ÿฌ๐Ÿฌ+ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—ณ๐—ผ๐—ฟ ๐—”๐˜‡๐˜‚๐—ฟ๐—ฒ, ๐—”๐—œ, ๐—–๐˜†๐—ฏ๐—ฒ๐—ฟ๐˜€๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ถ๐˜๐˜† & ๐— ๐—ผ๐—ฟ๐—ฒ ๐Ÿš€

Learn the most in-demand tech skills from Microsoft completely FREE๐ŸŒŸ

Microsoft Learn offers 100+ free courses designed to help students, freshers, and professionals build job-ready skills in today's fastest-growing technology domains.

โœ… 100% Free Learning
โœ… Beginner to Advanced Levels

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/4f0GNuH

๐Ÿš€ Learn. Practice. Upskill. Get Career Ready
โค2๐Ÿ‘Ž1
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:

You have 2 minutes to solve this SQL query.

Find the employees who have the highest salary in each department.

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
    employee_id,
    employee_name,
    department,
    salary
FROM (
    SELECT
        employee_id,
        employee_name,
        department,
        salary,
        DENSE_RANK() OVER (
            PARTITION BY department
            ORDER BY salary DESC
        ) AS rnk
    FROM employees
) ranked
WHERE rnk = 1;


๐Ÿ’ก Explanation:

This query uses the DENSE_RANK() window function to rank employees by salary within each department.

โ€ข PARTITION BY department creates separate rankings for each department.

โ€ข ORDER BY salary DESC ranks the highest salary as 1.

โ€ข DENSE_RANK() ensures that if multiple employees have the same highest salary, they all receive Rank 1.

โ€ข The outer query filters only the employees with rnk = 1.

This question tests your knowledge of:

โœ… Window Functions

โœ… DENSE_RANK() vs RANK() vs ROW_NUMBER()

โœ… Partitioning Data

๐ŸŽฏ Output Example

Employee | Department | Salary

John | IT | 95,000

Sarah | HR | 80,000

David | Finance | 90,000

Alice | IT | 95,000

(John and Alice both appear because they share the highest salary in the IT department.)

๐Ÿš€ Whenever an interview question asks for the top N records per group, think of window functions.

DENSE_RANK(), RANK(), and ROW_NUMBER() are among the most commonly tested SQL concepts.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค16
๐Ÿ“Š ๐—ฃ๐˜„๐—– ๐—ถ๐˜€ ๐—ผ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ถ๐—ป๐—ด ๐—ฎ ๐—™๐—ฅ๐—˜๐—˜ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ

This helps tolearn data visualization, dashboard creation, KPI analysis, and business intelligence skills that companies actively look for.

โœ… Free Certificate
โœ… Self-Paced Learning
โœ… Hands-On Power BI Projects
โœ… Beginner Friendly
โœ… Resume & LinkedIn Boost

Don't miss this opportunity to add an in-demand skill to your profile and stand out from the crowd! ๐Ÿ’ผ๐Ÿ”ฅ

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/4g5sKFa

Share with yours friends who wants to start a career in Data Analytics
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find employees whose salary is higher than their manager's salary.

Assume the table structure is:

employees(employee_id, employee_name, manager_id, salary)

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
e.employee_id,
e.employee_name,
e.salary AS employee_salary,
m.employee_name AS manager_name,
m.salary AS manager_salary
FROM employees e
JOIN employees m
ON e.manager_id = m.employee_id
WHERE e.salary > m.salary;

๐Ÿ’ก Explanation:

This query uses a self join because both employees and managers are stored in the same table.

โ€ข e represents the employee.
โ€ข m represents the manager.
โ€ข The join matches each employee with their manager using manager_id.
โ€ข The WHERE clause filters employees whose salary is greater than their manager's salary.

This question tests your understanding of:
โœ… Self Joins
โœ… Aliases (e and m)
โœ… Comparing values across related rows

๐ŸŽฏ Expected Output Example

Employee Employee Salary Manager Manager Salary

John 90,000 David 80,000
Sarah 85,000 Michael 75,000


๐Ÿš€ Self joins are one of the most frequently asked SQL interview topics. Practice scenarios involving employees, managers, organizational hierarchies, categories, and parent-child relationships.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค17
๐Ÿ“Š ๐—™๐—ฅ๐—˜๐—˜ ๐—ง๐—ฎ๐˜๐—ฎ ๐——๐—ฎ๐˜๐—ฎ ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ ๐—ฉ๐—ถ๐—ฟ๐˜๐˜‚๐—ฎ๐—น ๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐—ป๐˜€๐—ต๐—ถ๐—ฝ | ๐—ช๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ ๐Ÿš€

Here's an amazing opportunity to complete the FREE Tata Data Analytics Virtual Internship and earn a certificate that you can showcase on your Resume and LinkedIn.

โœ… 100% FREE
โœ… Self-Paced & Online
โœ… Beginner-Friendly
โœ… Certificate on Completion
โœ… Real Business Case Studies
โœ… Resume & LinkedIn Boost

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/4eybW8J

๐Ÿš€ Upskill Today. Build Your Portfolio. Get Career Ready!
โค9
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:

You have 2 minutes to solve this SQL query.

Find the top 3 highest-paid employees in each department.

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT

    employee_id,

    employee_name,

    department,

    salary

FROM (

    SELECT

        employee_id,

        employee_name,

        department,

        salary,

        DENSE_RANK() OVER (

            PARTITION BY department

            ORDER BY salary DESC

        ) AS salary_rank

    FROM employees

) ranked

WHERE salary_rank <= 3

ORDER BY department, salary DESC;

๐Ÿ’ก Explanation:

The query uses the DENSE_RANK() window function to rank employees based on salary within each department.

โ€ข PARTITION BY department creates a separate ranking for every department.

โ€ข ORDER BY salary DESC ranks the highest salary first.

โ€ข DENSE_RANK() assigns the same rank to employees with identical salaries.

โ€ข The outer query returns only employees with a rank of 3 or less.

This question tests your understanding of:

โœ… Window Functions

โœ… DENSE_RANK()

โœ… Top N per Group

โœ… Partitioning Data

๐ŸŽฏ Expected Output Example

Employee  Department Salary Rank

John  IT  95,000 1

Alice  IT  95,000 1

Bob  IT  90,000 2

Mike  IT  85,000 3

Sarah  HR  80,000 1

๐Ÿš€ Know when to use each ranking function:

โ€ข ROW_NUMBER() โ†’ No ties (unique ranking)

โ€ข RANK() โ†’ Leaves gaps after ties

โ€ข DENSE_RANK() โ†’ No gaps after ties (ideal for Top N with ties)

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค22
๐Ÿ“Š ๐—™๐—ฅ๐—˜๐—˜ ๐——๐—ฎ๐˜๐—ฎ ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ | ๐—ก๐—ผ ๐—˜๐˜…๐—ฝ๐—ฒ๐—ฟ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—ก๐—ฒ๐—ฒ๐—ฑ๐—ฒ๐—ฑ! ๐Ÿš€

Want to start a career in Data Analytics but don't know where to begin?

These 5 FREE beginner-friendly courses will help you learn the most in-demand data skills and build a strong foundation.

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/3SOk64h

๐Ÿš€ Start Learning Today. Build Your Portfolio. Land Your Dream Data Job!
โค1
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find customers who have never placed an order.

Tables:

customers(customer_id, customer_name)

orders(order_id, customer_id, order_date)


๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
c.customer_id,
c.customer_name
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.customer_id IS NULL;

๐Ÿ’ก Explanation:

This query uses a LEFT JOIN to return all customers, whether or not they have placed an order.

โ€ข LEFT JOIN keeps every customer in the result.
โ€ข Customers without matching records in the orders table will have NULL values.
โ€ข The WHERE o.customer_id IS NULL condition filters only customers who have never placed an order.

This question tests your understanding of:
โœ… LEFT JOIN
โœ… Finding missing records
โœ… NULL handling

๐ŸŽฏ Expected Output Example

Customer ID Customer Name

105 Alice
112 David
118 Sarah


๐Ÿš€ Questions about finding unmatched records are very common in interviews. Practice using:

- LEFT JOIN ... IS NULL

- NOT EXISTS

- NOT IN (carefully, because NULL values can affect results)

Among these, NOT EXISTS is often preferred for correctness and performance in many databases.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค11๐Ÿ”ฅ1
๐—ง๐—–๐—ฆ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ข๐—ป ๐——๐—ฎ๐˜๐—ฎ ๐— ๐—ฎ๐—ป๐—ฎ๐—ด๐—ฒ๐—บ๐—ฒ๐—ป๐˜ - ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ˜

TCS iON is offering a FREE Master Data Management Course with a Certificate,

โœ… 100% FREE Learning
โœ… Certificate on Completion
โœ… Self-Paced Online Course
โœ… Beginner-Friendly Content
โœ… Industry-Relevant Skills
โœ… Resume & LinkedIn Profile Boost

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/4jGFBw0

๐Ÿš€ Start Learning Today. Upskill for Free. Get Career Ready!
โค3๐Ÿ‘1๐Ÿฅฐ1
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find the department with the highest average salary.

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
department,
AVG(salary) AS average_salary
FROM employees
GROUP BY department
ORDER BY average_salary DESC
LIMIT 1;

๐Ÿ’ก Explanation:
The query calculates the average salary for each department and returns the department with the highest average salary.

โ€ข GROUP BY department groups employees by department
โ€ข AVG(salary) calculates the average salary for each department
โ€ข ORDER BY average_salary DESC sorts departments from highest to lowest average salary
โ€ข LIMIT 1 returns only the top department

This question tests your understanding of:
โœ… GROUP BY
โœ… Aggregate Functions AVG
โœ… ORDER BY
โœ… LIMIT

๐ŸŽฏ Expected Output
Department Average_Salary
IT 88,500

๐Ÿš€ Bonus Handles Ties
If multiple departments share the highest average salary, use DENSE_RANK():

SELECT
department,
average_salary
FROM (
SELECT
department,
AVG(salary) AS average_salary,
DENSE_RANK() OVER (
ORDER BY AVG(salary) DESC
) AS rnk
FROM employees
GROUP BY department
) ranked
WHERE rnk = 1;

This version returns all departments tied for the highest average salary.

๐Ÿš€ Whenever you see questions like highest, lowest, top N, or rank, think beyond LIMIT. Ask yourself: What if there's a tie? Window functions like DENSE_RANK() often provide a more complete solution.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค15
๐Ÿš€ ๐—ก๐—ฉ๐—œ๐——๐—œ๐—” ๐—™๐—ฅ๐—˜๐—˜ ๐—”๐—œ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ | ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป ๐—™๐—ฟ๐—ผ๐—บ ๐—”๐—œ ๐—œ๐—ป๐—ฑ๐˜‚๐˜€๐˜๐—ฟ๐˜† ๐—Ÿ๐—ฒ๐—ฎ๐—ฑ๐—ฒ๐—ฟ๐˜€

Want to build cutting-edge *AI skills* from one of the world's leading AI and GPU companies?

*NVIDIA* offers *FREE AI Certification Courses* to help students, freshers, developers, and professionals

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlinks.in/nvdia

๐Ÿš€ Start Learning Today. Earn Your Certificate. Build Your Future in AI!
โค1
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find employees who earn the same salary as at least one other employee in the same department.

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช
SELECT
employee_id,
employee_name,
department,
salary
FROM employees
WHERE (department, salary) IN (
SELECT
department,
salary
FROM employees
GROUP BY department, salary
HAVING COUNT(*) > 1
)
ORDER BY department, salary DESC;

๐Ÿ’ก Explanation:
The query identifies duplicate salary values within each department.

โ€ข The subquery groups records by department and salary.
โ€ข **HAVING COUNT(*) > 1** finds salary values that appear more than once in the same department.
โ€ข The outer query returns all employees whose (department, salary) matches those duplicate combinations.

This question tests your understanding of:
โœ… GROUP BY
โœ… HAVING
โœ… Multi-column filtering
โœ… Identifying duplicate records

๐ŸŽฏ Expected Output Example
Employee Department Salary
John IT 80,000
Alice IT 80,000
David HR 65,000
Sarah HR 65,000

๐Ÿš€ Alternative Using Window Functions
SELECT
employee_id,
employee_name,
department,
salary
FROM (
SELECT
*,
COUNT(*) OVER (
PARTITION BY department, salary
) AS salary_count
FROM employees
) t
WHERE salary_count > 1;

This approach avoids a subquery with GROUP BY and is a great way to showcase your knowledge of window functions.

๐Ÿš€ When interview questions ask you to find duplicates, think of these three approaches:

1. GROUP BY + HAVING
2. Window functions COUNT() OVER
3. Self Join for specific comparison scenarios

Knowing multiple solutions demonstrates strong SQL problem-solving skills.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค11
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find the third highest salary from the employees table without using LIMIT or TOP.

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
salary
FROM (
SELECT
salary,
DENSE_RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM employees
) ranked
WHERE salary_rank = 3;

๐Ÿ’ก Explanation:
This query uses the DENSE_RANK() window function to rank distinct salary values in descending order.

โ€ข ORDER BY salary DESC assigns Rank 1 to the highest salary.
โ€ข DENSE_RANK() ensures duplicate salaries receive the same rank.
โ€ข The outer query filters for salary_rank = 3, returning the third highest distinct salary.

๐ŸŽฏ Expected Output Example
Salary Rank
95,000 1
90,000 2
85,000 3

Output:
Third Highest Salary
85,000

๐Ÿš€ Alternative Solution Using a Correlated Subquery
SELECT DISTINCT salary
FROM employees e1
WHERE 2 = (
SELECT COUNT(DISTINCT salary)
FROM employees e2
WHERE e2.salary > e1.salary
);

This solution avoids window functions and is commonly asked to test your understanding of correlated subqueries.

๐Ÿš€ Questions involving the Nth highest or Nth lowest value are interview favorites. Be comfortable solving them using:

1. DENSE_RANK()
2. RANK()
3. Correlated Subqueries
4. Common Table Expressions (CTEs)

Being able to provide multiple approaches leaves a strong impression on interviewers.

โค๏ธ React with โค๏ธ for more interview challenges!
โค17
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find the employees who joined in the last 30 days.

Assume the table structure:
employees(employee_id, employee_name, department, joining_date)

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
employee_id,
employee_name,
department,
joining_date
FROM employees
WHERE joining_date >= CURRENT_DATE - INTERVAL '30 days';

๐Ÿ’ก Explanation:
This query filters employees whose joining date falls within the last 30 days.

โ€ข CURRENT_DATE returns today's date.
โ€ข INTERVAL '30 days' subtracts 30 days from the current date.
โ€ข The WHERE clause returns employees who joined on or after that date.

This question tests your understanding of:
โœ… Date Functions
โœ… Date Arithmetic
โœ… Filtering Records with Dates

๐ŸŽฏ Expected Output Example
Employee Department Joining Date
John IT 2026-06-10
Sarah HR 2026-06-22

๐Ÿš€ Database-Specific Alternatives

MySQL
SELECT *
FROM employees
WHERE joining_date >= CURDATE() - INTERVAL 30 DAY;

SQL Server
SELECT *
FROM employees
WHERE joining_date >= DATEADD(DAY, -30, GETDATE());

Oracle
SELECT *
FROM employees
WHERE joining_date >= SYSDATE - 30;

๐Ÿš€ Tip for SQL Job Seekers:
Date-related SQL questions are very common. Make sure you're comfortable with:
โ€ข Finding records from the last N days
โ€ข Current month/year filters
โ€ข Date differences
โ€ข Date formatting
โ€ข Database-specific date functions

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค19
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.

Find the customer(s) who placed the highest number of orders.

Tables:
customers(customer_id, customer_name)
orders(order_id, customer_id, order_date)

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
customer_id,
customer_name,
total_orders
FROM (
SELECT
c.customer_id,
c.customer_name,
COUNT(o.order_id) AS total_orders,
DENSE_RANK() OVER (
ORDER BY COUNT(o.order_id) DESC
) AS rnk
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id
GROUP BY
c.customer_id,
c.customer_name
) ranked
WHERE rnk = 1;


๐Ÿ’ก Explanation:
The query first counts the total number of orders placed by each customer and then ranks them based on the order count.

โœ… COUNT(o.order_id) calculates the number of orders per customer.

โœ… GROUP BY ensures one row per customer.

โœ… DENSE_RANK() ranks customers from highest to lowest order count.

โœ… The outer query returns all customers with rnk = 1, including ties.

This question tests your understanding of:

โœ… JOIN

โœ… GROUP BY

โœ… Aggregate Functions COUNT

โœ… Window Functions DENSE_RANK

๐ŸŽฏ Expected Output Example

+----------+--------------+
| Customer | Total Orders |
+----------+--------------+
| John | 25 |
| Sarah | 25 |
+----------+--------------+


Both customers are returned because they are tied for the highest number of orders.

๐Ÿš€ Tip for SQL Job Seekers:
Whenever an interview asks for the highest, lowest, most, or least, think about whether multiple records could tie for first place. Using DENSE_RANK() instead of LIMIT 1 makes your solution more robust and interview-ready.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค18
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.
Find all employees who have the same manager.

Assume the table structure:
employees(employee_id, employee_name, manager_id)

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช

SELECT
e.employee_id,
e.employee_name,
e.manager_id,
m.employee_name AS manager_name
FROM employees e
JOIN employees m
ON e.manager_id = m.employee_id
WHERE e.manager_id IN (
SELECT manager_id
FROM employees
WHERE manager_id IS NOT NULL
GROUP BY manager_id
HAVING COUNT(*) > 1
)
ORDER BY e.manager_id, e.employee_name;

๐Ÿ’ก Explanation:
This query identifies managers who supervise more than one employee and returns all employees reporting to those managers.

โœ… The subquery groups records by manager_id.

โœ… HAVING COUNT(*) > 1 finds managers with multiple direct reports.

โœ… A self join retrieves the manager's name.

โœ… The outer query returns every employee reporting to those managers.

This question tests your understanding of:
โœ… Self Joins
โœ… GROUP BY and HAVING
โœ… Subqueries
โœ… Organizational Hierarchies

๐ŸŽฏ Expected Output Example
Employee Manager
John David
Alice David
Sarah Michael
Bob Michael

๐Ÿš€ Alternative Using Window Functions
SELECT
employee_id,
employee_name,
manager_id
FROM (
SELECT
*,
COUNT(*) OVER (
PARTITION BY manager_id
) AS team_size
FROM employees
WHERE manager_id IS NOT NULL
) t
WHERE team_size > 1;

This approach uses a window function to count the number of employees under each manager without using GROUP BY.

๐Ÿš€ Tip for SQL Job Seekers:
Hierarchy-based questions are very common in interviews. Practice problems involving:
Employees and managers
Parent-child relationships
Organizational charts
Category trees
Recursive queries WITH RECURSIVE or recursive CTEs

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค15
๐Ÿถ ASO Corgi โ€” platform for the App Store developers.
Find the keywords your apps and competitors rank for, and track positions across every country in one place.
๐Ÿ”‘ Keyword research: by topic, by your app's languages, from App Store suggestions, by competitors, and with AI analysis.
โ€ข Rankings by country โ€” history, charts, demand score (0โ€“100)
โ€ข Global search across any App Store storefront
โ€ข ASO assistant builds your listing for each locale
โ€ข App Store top charts for any country

๐ŸŽ 14 days of Pro, free ๐Ÿ‘‡ (no card required)
https://asocorgi.com/?promo=promo14&utm_source=sqlspecialist&utm_medium=telegram&utm_campaign=launch
โค5
๐—•๐—ผ๐—ผ๐˜€๐˜ ๐—ฌ๐—ผ๐˜‚๐—ฟ ๐—–๐—ฎ๐—ฟ๐—ฒ๐—ฒ๐—ฟ ๐–๐ข๐ญ๐ก ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ + ๐—ฆ๐—ต๐—ผ๐˜„๐—ฐ๐—ฎ๐˜€๐—ฒ ๐——๐—ถ๐—ด๐—ถ๐˜๐—ฎ๐—น ๐—•๐—ฎ๐—ฑ๐—ด๐—ฒ๐˜€

๐Ÿ’ซStand out in the job market with globally recognized tech skills

โœ… 100% FREE Learning
โœ… Official Cisco Digital Badges
โœ… Self-Paced Online Courses
โœ… Beginner-Friendly Content
โœ… Hands-on Labs (Selected Courses)
โœ… Globally Recognized Skills

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/4y0ACOI

๐Ÿš€ Start Learning Today. Earn Official Cisco Badges. Get Career Ready!
โค4
๐—œ๐—ป๐˜๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฒ๐˜„๐—ฒ๐—ฟ:
You have 2 minutes to solve this SQL query.
Find the departments where the average salary is greater than the company's overall average salary.

๐— ๐—ฒ: Challenge accepted! ๐Ÿ’ช
SELECT
department,
AVG(salary) AS average_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > (
SELECT AVG(salary)
FROM employees
);

๐Ÿ’ก Explanation:
The query compares each department's average salary with the company's overall average salary.

โ€ข GROUP BY department calculates the average salary for each department.
โ€ข The subquery computes the overall average salary across all employees.
โ€ข HAVING filters only those departments whose average salary exceeds the company average.

This question tests your understanding of:
โœ… GROUP BY
โœ… HAVING
โœ… Aggregate Functions AVG
โœ… Subqueries

๐ŸŽฏ Expected Output Example
Department: Average Salary
IT: 88,500
Finance: 84,000

HR is excluded because its average salary is below the company average.

๐Ÿš€ Alternative Using a Common Table Expression CTE
WITH company_avg AS (
SELECT AVG(salary) AS avg_salary
FROM employees
)
SELECT
department,
AVG(salary) AS average_salary
FROM employees, company_avg
GROUP BY department, company_avg.avg_salary
HAVING AVG(salary) > company_avg.avg_salary;

Using a CTE can improve readability, especially when the same calculated value is reused in larger queries.

๐Ÿš€ Tip for SQL Job Seekers:
Interviewers often ask questions that compare group-level aggregates with overall aggregates. Master the use of HAVING with subqueriesโ€”itโ€™s a key SQL pattern.

โค๏ธ React with โค๏ธ for more SQL interview challenges!
โค12
๐Ÿš€ ๐—š๐—ผ๐—ผ๐—ด๐—น๐—ฒ ๐—™๐—ฅ๐—˜๐—˜ ๐—”๐—œ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐—ช๐—ถ๐˜๐—ต ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ถ๐—ผ๐—ป ๐—•๐—ฎ๐—ฑ๐—ด๐—ฒ๐˜€ ๐Ÿ”ฅ

Google is offering free AI courses with completion badges to help students & professionals build in-demand AI skills ๐ŸŒ

โœจ Learn from Google Experts
โœจ Earn Google Completion Badges
โœจ Boost Your Resume & LinkedIn Profile
โœจ Build In-Demand AI Skills for 2026

๐Ÿ”— ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:

https://pdlink.in/49lCYxa

๐Ÿ”ฅ Start your AI journey today and future-proof your career with Google AI learning programs.
โค3