当前位置:网站首页>LeetCode-1303. Team size
LeetCode-1303. Team size
2022-06-12 06:23:00 【Border wanderer】
The employee table :Employee
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| employee_id | int |
| team_id | int |
+---------------+---------+
employee_id The field is the primary key of this table , Each row in the table contains the for each employee ID And their team .
Write a SQL Inquire about , To find the total number of people in each employee's team .
There are no specific requirements for the order in the query results .
An example of query result format is as follows :
Employee Table:
+-------------+------------+
| employee_id | team_id |
+-------------+------------+
| 1 | 8 |
| 2 | 8 |
| 3 | 8 |
| 4 | 7 |
| 5 | 9 |
| 6 | 9 |
+-------------+------------+
Result table:
+-------------+------------+
| employee_id | team_size |
+-------------+------------+
| 1 | 3 |
| 2 | 3 |
| 3 | 3 |
| 4 | 1 |
| 5 | 2 |
| 6 | 2 |
+-------------+------------+
ID by 1、2、3 Our employees are team_id by 8 Members of our team ,
ID by 4 Our employees are team_id by 7 Members of our team ,
ID by 5、6 Our employees are team_id by 9 Members of our team .
# Write your MySQL query statement below
# Parent query left connection , Being a father team_id With son team_id Equal is enough
SELECT e1.employee_id, e2.team_size FROM Employee AS e1 LEFT JOIN
(
# The subquery first finds each team_id Of team_size
SELECT team_id AS tmp_id, COUNT(team_id) AS team_size FROM Employee
GROUP BY team_id
) AS e2 ON e1.team_id = e2.tmp_id;边栏推荐
猜你喜欢

The vs 2019 community version Microsoft account cannot be logged in and activated offline

Multithreading (V) -- concurrency tools (I) -- thread pool (II) -- related contents of ThreadPoolExecutor

Redis problem (I) -- cache penetration, breakdown, avalanche

How do I get the date and time from the Internet- How to get DateTime from the internet?

Word2Vec

(UE4 4.27) add globalshder to the plug-in

Houdini & UE4 programmed generation of mountains and multi vegetation scattering points

Redis configuration (IV) -- cluster

In unity3d, billboard effect can be realized towards another target

Modifying theme styles in typora
随机推荐
Storing texture2d to hard disk JPG file with script under unity3d
Multithreading mode (I) -- protective pause and join source code
(UE4 4.27) add globalshder to the plug-in
夜神模擬器adb查看log
Leetcode personal question solution (Sword finger offer3-5) 3 Duplicate number in array, 4 Find in 2D array, 5 Replace spaces
Redis problem (I) -- cache penetration, breakdown, avalanche
Modifying theme styles in typora
Multithreading (2) -- pipeline (2) -- synchronized underlying monitor, lightweight, biased lock, lock inflation
Logistic regression model
Qt-- realize TCP communication
Cross compile libev
Redis queue
Cause analysis of motion blur / smear caused by camera shooting moving objects
English grammar_ Adverb_ With or without ly, the meaning is different
SQL 注入-盲注
Redis data structure (VIII) -- Geo
UE4 4.27 modify the mobile forward pipeline to support cluster multi light source culling
Tips for using the potplayer video player
C2w model - language model
摄像头拍摄运动物体,产生运动模糊/拖影的原因分析