Skip to content

Commit 38cbcf3

Browse files
add 1075
1 parent aadf147 commit 38cbcf3

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ _If you like this project, please leave me a star._ ★
855855
|1084|[Sales Analysis III](https://leetcode.com/problems/sales-analysis-iii/)|[Solution](../master/database/_1084.sql) | | Easy |
856856
|1083|[Sales Analysis II](https://leetcode.com/problems/sales-analysis-ii/)|[Solution](../master/database/_1083.sql) | | Easy |
857857
|1082|[Sales Analysis I](https://leetcode.com/problems/sales-analysis-i/)|[Solution](../master/database/_1082.sql) | | Easy |
858+
|1075|[Project Employees I](https://leetcode.com/problems/project-employees-i/)|[Solution](../master/database/_1075.sql) | | Easy |
858859
|1069|[Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii/)|[Solution](../master/database/_1069.sql) | | Easy |
859860
|1068|[Product Sales Analysis I](https://leetcode.com/problems/product-sales-analysis-i/)|[Solution](../master/database/_1068.sql) | | Easy |
860861
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/)|[Solution](../master/database/_627.sql) | | Easy |

database/_1075.sql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--1075. Project Employees I
2+
--
3+
--Table: Project
4+
--
5+
--+-------------+---------+
6+
--| Column Name | Type |
7+
--+-------------+---------+
8+
--| project_id | int |
9+
--| employee_id | int |
10+
--+-------------+---------+
11+
--(project_id, employee_id) is the primary key of this table.
12+
--employee_id is a foreign key to Employee table.
13+
--Table: Employee
14+
--
15+
--+------------------+---------+
16+
--| Column Name | Type |
17+
--+------------------+---------+
18+
--| employee_id | int |
19+
--| name | varchar |
20+
--| experience_years | int |
21+
--+------------------+---------+
22+
--employee_id is the primary key of this table.
23+
--
24+
--
25+
--Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.
26+
--
27+
--The query result format is in the following example:
28+
--
29+
--Project table:
30+
--+-------------+-------------+
31+
--| project_id | employee_id |
32+
--+-------------+-------------+
33+
--| 1 | 1 |
34+
--| 1 | 2 |
35+
--| 1 | 3 |
36+
--| 2 | 1 |
37+
--| 2 | 4 |
38+
--+-------------+-------------+
39+
--
40+
--Employee table:
41+
--+-------------+--------+------------------+
42+
--| employee_id | name | experience_years |
43+
--+-------------+--------+------------------+
44+
--| 1 | Khaled | 3 |
45+
--| 2 | Ali | 2 |
46+
--| 3 | John | 1 |
47+
--| 4 | Doe | 2 |
48+
--+-------------+--------+------------------+
49+
--
50+
--Result table:
51+
--+-------------+---------------+
52+
--| project_id | average_years |
53+
--+-------------+---------------+
54+
--| 1 | 2.00 |
55+
--| 2 | 2.50 |
56+
--+-------------+---------------+
57+
--The average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50
58+
59+
--# Write your MySQL query statement below
60+
select project_id, round(avg(experience_years), 2) as average_years
61+
from Project
62+
join Employee
63+
using (employee_id)
64+
group by project_id
65+
order by project_id

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy