Count Employees - SQL Interview Query 13 | SQL Problem Level 'EASY'

preview_player
Показать описание
30DaySQLQueryChallenge is a series of 30 videos covering 30 SQL Interview Queries. This is the THIRTEENTH video in this series. This video series aims to provide 30 SQL Queries that can be asked during SQL Interviews. I will explain how to solve and address such SQL queries during interviews in these videos.

Let's follow the below routine to make the best use of it:
1. Watch the YouTube video (first half) to understand the problem statement.

2. Go to my discord server (link below), download the dataset for each problem, and try solving it yourself.

3. Share your solution on Discord and discuss different solutions and issues on my Discord server.

4. Watch the second half of my YouTube video to find my solution to the problem.

5. Share it with your contacts and spread the knowledge.

DOWNLOAD the Dataset from below:

Timeline:
00:00 Intro
00:10 Understanding Problem Statement
00:37 Solution to the SQL Problem

Thanks for participating in this challenge!

Good luck and Happy Learning!
Рекомендации по теме
Комментарии
Автор

with cte as (
select manager as manager_id, count(1)
from employee_managers
where manager is not null
group by manager
)
select b.name, a.count
from cte a
join employee_managers b on a.manager_id=b.id

Kirankumar-mlro
Автор

Hi i am a great admirer of your work think there is no point in giving toughest challenge for challenge sake watch these videos for either interview sake or to use in their work ....i wish plz try to cover all kind of queries that would be useful for interview and work, in that process plz try to include all sql concepts, built in functions that kind of revision of all sql concepts is just my wish

krishna
Автор

Toufiq, can you please take one problem from materialized view ?

akashchristopher
Автор

select name, num from employee_managers a inner join
(select manager, count(distinct id) as num from employee_managers group by 1)b
on a.id=b.manager
order by 2 desc

shivinmehta
Автор

Hi toufiq, can solve problems regarding FIFO in SQL
How we apply FIFO for calculating Holding & PNL while buying stock

dmrockers
Автор

Can you please teach us M query language

minakemkar
Автор

select a.name, count(b.name) no_of_employees
from employee_managers a
join employee_managers b on a.id=b.manager
group by a.name
order by 2 desc

Alexpudow
Автор

Hey toufiq, are you giving the problems in increasing difficulties? Because today is the first day I found you video and I'd like to follow it from today rather than rushing from day 1. i want to do them later when I finish with you.

junaidmahmud
Автор

select b.name, count(*)
from employee_managers a
join employee_managers b
on a.manager = b.id
group by b.name
order by count(*) desc;

radhikamaheshwari
Автор

with cte as (
select e.id emp_id, e.name as emp_name, e.manager as mag_id, m.name as mang_name from employee_managers m
inner join employee_managers e
on e.manager=m.id)
select mang_name as manager, no_of_employee_under_this_manager from (
select mang_name,
count(mang_name) over(partition by mag_id) as
from cte)x
group by mang_name, no_of_employee_under_this_manager
order by desc;

akriti-
Автор

Hi toufiq, by the end of this series can you give atleast 1 extremely almost unsolvable problem which you might have encountered in a real world scenario? So far the questions are very good but the difficulty level of all 13 problems were not very high.

Tusharchitrakar
Автор

select distinct e2.name, count(1) as no_of_employees
from employee_managers e1
join employee_managers e2
on e1.manager=e2.id
group by e2.name
order by no_of_employees desc;

Shubham-g
Автор

with CTE1 as
(select distinct manager
, count(manager) over(partition by manager) as no_of_employees
from employee_managers
where manager is not null)
select em1.NAME as Manager
, c1.No_of_Employees
from CTE1 c1
join employee_managers em1
on c1.manager = em1.id
order by c1.No_of_Employees desc;

MojilShah
Автор

Select A.Name, Count(B.MGR) from Day_13 A join Day_13 B
On A.ID=B.MGR Group by A.Name;

narendrashekhavat
Автор

For PG admin

SELECT m.name AS manager, COUNT(1) AS count_of_employees FROM employee_managers e JOIN employee_managers m
ON e.manager = m.id
GROUP BY m.name
ORDER BY count_of_employees DESC

ArnabGhosh-prbm
Автор

with employee as (
select e.id as emp_id, e.name as emp_name, m.id as manager_id, m.name as manager_name
from employee_managers e
join employee_managers m on m.id=e.manager
)

select manager_name, count(manager_id) as no_of_employees
from employee
group by manager_name
order by no_of_employees desc, manager_name ;

rahultalwar
welcome to shbcf.ru