Managers with at Least 5 Direct Reports - Leetcode 570 | Week 4 | Qs 16

  Рет қаралды 978

The Big Data Show

The Big Data Show

2 жыл бұрын

Leetcode - 570. Managers with at Least 5 Direct Reports
Do Like, Comment & Subscribe...
𝗝𝗼𝗶𝗻 𝗺𝗲 𝗼𝗻 𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
🔅 LinkedIn - / ankur-ranjan-35787414b
🔅 Instagram - / ranjan_anku
SQL Question
Write an SQL query to report the managers with at least five direct reports.
SQL Schema
Create table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)
Truncate table Employee
insert into Employee (id, name, department, managerId) values ('101', 'John', 'A', 'None')
insert into Employee (id, name, department, managerId) values ('102', 'Dan', 'A', '101')
insert into Employee (id, name, department, managerId) values ('103', 'James', 'A', '101')
insert into Employee (id, name, department, managerId) values ('104', 'Amy', 'A', '101')
insert into Employee (id, name, department, managerId) values ('105', 'Anne', 'A', '101')
insert into Employee (id, name, department, managerId) values ('106', 'Ron', 'B', '101')
Table: Employee
+-----------------------+--------------+
| Column Name | Type |
+-----------------------+--------------+
| id | int |
| name | varchar |
| department | varchar |
| managerId | int |
+----------------------+--------------+
id is the primary key column for this table.
Each row of this table indicates the name of an employee, their department, and the id of their manager.
If managerId is null, then the employee does not have a manager.
No employee will be the manager of themself.
Write an SQL query to report the managers with at least five direct reports.
Return the result table in any order.
The query result format is in the following example.
Example 1:
Input:
Employee table:
+-----+-------------+--------------------+-----------------+
| id | name | department | managerId |
+-----+-------------+--------------------+-----------------+
| 101 | John | A | None |
| 102 | Dan | A | 101 |
| 103 | James | A | 101 |
| 104 | Amy | A | 101 |
| 105 | Anne | A | 101 |
| 106 | Ron | B | 101 |
+-----+-------------+-------------------+-----------------+
Output:
+------+
| name |
+------+
| John |
+------+

Пікірлер: 2
@vishalbhandari8875
@vishalbhandari8875 Ай бұрын
WHAT AN EXPLANATION. KEEP UP THE GOOD WORK
@adityasaini8437
@adityasaini8437 8 ай бұрын
I am have a doubt , how inner join working here ? as it defines inner join tables on matching column values , now according to your on cond. e. managerID = m.id , we have only one matching column then why we are getting all the value as output
Find the output after every JOIN like Left, Right & inner. #sql #interview
1:00
Каха ограбил банк
01:00
К-Media
Рет қаралды 11 МЛН
Sigma Girl Past #funny #sigma #viral
00:20
CRAZY GREAPA
Рет қаралды 32 МЛН
LeetCode 570: Managers with at Least 5 Direct Reports [SQL]
6:46
Frederik Müller
Рет қаралды 6 М.
Intro To Databricks - What Is Databricks
12:28
Seattle Data Guy
Рет қаралды 222 М.
What is ETL | What is Data Warehouse | OLTP vs OLAP
8:07
codebasics
Рет қаралды 406 М.
LeetCode Medium 1934 Interview SQL Question with Detailed Explanation
11:47
Everyday Data Science
Рет қаралды 6 М.
Study Plan To Master SQL🔥✅️🎯 #sql #mysql
0:59
BEPEC by Kanth - #BuildExperience & Get Hired!
Рет қаралды 58 М.
Каха ограбил банк
01:00
К-Media
Рет қаралды 11 МЛН