အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 7 အတွက်ကတော့ Leetcode ရဲ့ difficulty Medium level problem တစ်ပုဒ်ဖြစ်တဲ့ (570. Managers with at Least 5 Direct Reports) ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။

ဒီပုစ္ဆာ အတွက်ကတော့ Employee table တစ်ခုထဲပဲပေးထားပါတယ်။ ကျွန်တော်တို့က အနိမ့်ဆုံး ငါးခုနဲ့ အထက် Employee တွေက report လုပ်တဲ့ manager ရဲ့ name ကိုရှာပေးရမှာပဲဖြစ်ပါတယ်။
1*Example*
2
3Input:
4Employee table:
5+-----+-------+------------+-----------+
6| id | name | department | managerId |
7+-----+-------+------------+-----------+
8| 101 | John | A | null |
9| 102 | Dan | A | 101 |
10| 103 | James | A | 101 |
11| 104 | Amy | A | 101 |
12| 105 | Anne | A | 101 |
13| 106 | Ron | B | 101 |
14+-----+-------+------------+-----------+
15Output:
16+------+
17| name |
18+------+
19| John |
20+------+
21 manager id null ဖြစ်နေရင်တော့ manager မရှိဘူးပေါ့။ အဲ့တော့ ကျွန်တော်တို့ query လေးရေးလိုက်ရအောင်ဗျ။
1
2SELECT m.name FROM Employee m
3JOIN Employee e ON e.managerId = m.id
4GROUP BY m.name, m.id
5HAVING COUNT(e.id) >= 5;ဒီမှာဆို ကျွန်တော်ပထမဆုံး Employee ကို m (manager )လို့ alias ပေးထားတယ်ဗျ။ self join နဲ့ Employee e ရဲ့managerId က m (manager) ရဲ့ id နဲ့တူတာကို join ထားတယ်ပေါ့။ ဒီလို join လိုက်ခြင်းဖြင့် ကျွန်တော်တို့ manager တွေတော့ရလာခဲ့ပြီ အဲ့တော့ manager တွေတစ်ယောက်ခြင်းစီမှာ report ငါးခုအထက်ရှိမရှိစစ်ဖို့ တစ်ယောက်ခြင်းစီရဲ့ name,id ကို Group By လုပ်ထားလိုက်ပါတယ်။
Group By မှာ condition စစ်ချင်ရင် Having လေးကို အသုံးပြုရတာဖြစ်လို့ Having သုံးပြီး employee ရဲ့ id count ကို 5နဲ့ အထက်စစ်လိုက်ပါတယ်။ ဒါဆို report 5ခုနဲ့ခက်ရှိတဲ့ manager တွေကို ရရှိပြီပဲဖြစ်ပါတယ်ခင်ဗျာ။ Day 7 အတွက်ပုစ္ဆာလေးလည်းပြီးဆုံးခဲ့ပြီဗျာ။ Video လေးကိုတော့ထုံးစံအတိုင်း အောက်က YouTube link လေးကနေဝင်ရောက်ကြည့်ရှု့နိုင်ပါတယ်ဗျ။ Stay safe and see you all ပါဗျ။
30 Days Of LeetCode Database Challenge Day 7 - (570. Managers with at Least 5 Direct Reports)
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
Day 1 - Software Development ကို ပိုပြီးမြန်စေမယ့် CI/CD
Software တစ်ခုရေးပြီးပြီဆိုရင် "ငါ့စက်ထဲမှာတော့ အလုပ်လုပ်တယ်" ဆိုရုံနဲ့ မပြီးသေးပါဘူး။ User တွေသုံးမယ့် Server ပေါ်ရောက်...

Secure AWS ECR Github Action Using OIDC
Modern DevOps နှင့် Cloud Security တို့မှာ အဓိကဖြစ်လာသည့် Authentication System ယနေ့ခေတ် DevOps, Cloud Engineering, CI/C...

Manual vs Automated Infrastructure: Why "useradd" Still Matters in the Terraform Era
DevOps careerကို လျှောက်နေတဲ့သူတိုင်း Terraform၊ Ansible စတဲ့ Infrastructure as Code (IaC) tools တွေရဲ့ အလုပ်လုပ်နိုင်စွ...
From Surviving to Thriving
“AI ကြောင့် developer အလုပ်ပျောက်သွားမလား?” ဆိုတဲ့ မေးခွန်းကို Junior developer တိုင်း စဉ်းစားဖူးကြမှာပါ။ ဈေးကွက်အခြေအနေ...

AWS - Global Infra
AWS Global Infra AWS Global Infra & Service Type ဆိုတဲ့ ခေါင်းစဉ်နဲ့ ၂၀၂၅ ဒီဇင်ဘာမှာရေးထားဖူးတဲ့ article ကို အရင်ဆုံး ဖတ...

