အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 27 အတွက်ကတော့ Leetcode ရဲ့ difficulties Easy level problem တစ်ပုဒ်ဖြစ်တဲ့ 1075. Project Employees I ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ မှာတော့ Project and Employee ဆိုတဲ့ table လေးနှစ်ခုကိုပေးထားပါတယ်။
1Table: Project2 3+-------------+---------+4| Column Name | Type |5+-------------+---------+6| project_id | int |7| employee_id | int |8+-------------+---------+9(project_id, employee_id) is the primary key of this table.10employee_id is a foreign key to Employee table.11Each row of this table indicates that the employee with employee_id is working on the project with project_id.12 13 14Table: Employee15 16+------------------+---------+17| Column Name | Type |18+------------------+---------+19| employee_id | int |20| name | varchar |21| experience_years | int |22+------------------+---------+23employee_id is the primary key of this table. It's guaranteed that experience_years is not NULL.24Each row of this table contains information about one employee.25 26 27Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.28 29Return the result table in any order.30 31The query result format is in the following example.32 33 ကျွန်တော်တို့လုပ်ပေးဖို့လိုတာကတော့ Project တစ်ခုချင်းစီမှာရှိတဲ့ Employee တွေရဲ့ experience years တွေကို average ရှာပေးရမှာပဲဖြစ်ပါတယ်။ ရလာတဲ့ result ကိုလည်း decimal 2 နေရာစာ ROUND လုပ်ပေးရမှာပဲဖြစ်ပါတယ်။ Average တွက်ဖို့ဆိုရင် project တစ်ခုချင်းစီမှာရှိတဲ့ employee တွေရဲ့ စုစုပေါင်း experience years ကိုတည်ပြီး employee စုစုပေါင်းအရေအတွက်နဲ့စားပေးရမှာပဲဖြစ်ပါတယ်။
1Example 1:2 3Input: 4Project table:5+-------------+-------------+6| project_id | employee_id |7+-------------+-------------+8| 1 | 1 |9| 1 | 2 |10| 1 | 3 |11| 2 | 1 |12| 2 | 4 |13+-------------+-------------+14Employee table:15+-------------+--------+------------------+16| employee_id | name | experience_years |17+-------------+--------+------------------+18| 1 | Khaled | 3 |19| 2 | Ali | 2 |20| 3 | John | 1 |21| 4 | Doe | 2 |22+-------------+--------+------------------+23Output: 24+-------------+---------------+25| project_id | average_years |26+-------------+---------------+27| 1 | 2.00 |28| 2 | 2.50 |29+-------------+---------------+30Explanation: 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.5031 ကျွန်တော်ကတော့ အောက်ပါအတိုင်းရေးဖြစ်ခဲ့ပါတယ်ဗျာ။
1**SQL**2 3SELECT p.project_id,4ROUND(SUM(e.experience_years) / COUNT(e.employee_id), 2) AS average_years5FROM Project p JOIN Employee e ON e.employee_id = p.employee_id6GROUP BY p.project_id;ဒီ query မှာဆိုရင် project တစ်ခုချင်းစီရဲ့ average ကိုလိုချင်တာဖြစ်လို့ project _d နဲ့ **Group By **လုပ်လိုက်ပါတယ်။ Employee table ထဲက record တွေလည်းအသုံးပြုဖို့လိုတာမို့လို့ Project table ထဲမှာရှိတဲ့ employee_id နဲ့ Employee table ထဲက employee_id တို့ကို Inner Join လေး join လိုက်ပါတယ်။ ကျွန်တော်တို့တွက်ပေးဖို့လိုအပ်တဲ့အတိုင်း employee အကုန်လုံးရဲ့ စုစုပေါင်း Experience years ကိုတည်ပြီး employee စုစုပေါင်းအရေအတွက်နဲ့စားပြီး ရလာတဲ့ result ကို decimal 2 နေရာစာ ROUND လုပ်ပေးလိုက်ပါတယ်ဗျာ။
ဒါဆိုရင် လိုချင်တဲ့အဖြေလေးရရှိသွားပြီပဲဖြစ်ပါတယ်ဗျာ။ Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Day 27 - 1075. Project Employees I
Watch on YouTubeDiscussion
Join the conversation
How do you feel about this article?
Comments
Sign in to join the conversation
Sign in to be the first to comment!
Share Your Article
Share with your professional network
Recent Articles

AWS - Application Load Balancer
Elastic Load Balancing (ELB) ELB ဆိုတာကတော့ request တွေကို တစ်နေရာတည်းမှ လက်ခံကာ Amazon EC2 instances၊ containers, etc.....

Terraform Day 3: Benefits of Terraform State
Terraform ကိုလေ့လာ တဲ့အခါ ကျွန််တော်တို့ရဲ့ Project Folder ထဲမှာ terraform.tfstate ဆိုတဲ့ ဖိုင်လေးကို တွေ့ဖူးကြပါလိမ့်မယ...

Terraform Day 2: Essential IaC Principles You Must Know
မနေ့ကတော့ Terraform အကြောင်း အကြမ်းဖျင်း Concept ကို ပြောပြခဲ့ပြီးပြီဆိုတော့ ဒီနေ့မှာတော့ Terraform ကို Professional ကျက...

TCP/IP Protocol
အားလုံးပဲမင်္ဂလာပါ။ ဒီနေ့ ကျွန်တော်တို့ TCP/IP Protocol အကြောင်း ဆွေးနွေးသွားပါမယ်။ ပထမဆုံးအနေနဲ့ TCP/IP ရဲ့ History လေး...

Terraform Day 1: Introduction to IAC and Terraform
ကျွန်တော်တို့ cloud အကြောင်း စပြောကြပြီဆိုရင် အရင်ဆုံး ခေါင်းထဲရောက်လာတာ Console ထဲဝင်၊ UI ကနေ ခလုတ်လေးတွေ လိုက်နှိပ်ပြီ...


