30 Days Of LeetCode Database Challenge Day 5 - 185. Department Top Three Salaries (Difficulty Hard)

အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 5 အတွက်ကတော့ Leetcode ရဲ့ difficulties Hard level problem တစ်ပုဒ်ဖြစ်တဲ့ 185. Department Top Three Salaries ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ Employee နဲ့ Department ဆိုတဲ့ table နှစ်ခုပေးထားပါတယ်။

လိုချင်တာကတော့ Department တစ်ခုချင်းစီကနေ အမြင့်ဆုံးလစာ သုံးခု ရတဲ့ Employee တွေကို လိုချင်တာပဲဖြစ်ပါတယ်။ query လေး အောက်က အတိုင်းလေး ရေးကြည့်လိုက်ရအောင်ဗျာ။
1SELECT d.name AS Department, e.name AS Employee, e.salary AS Salary FROM Employee e JOIN Department d ON d.id = e.departmentId WHERE (
2 SELECT COUNT(DISTINCT esub.salary) FROM Employee esub where esub.departmentId = e.departmentId AND esub.salary >= e.salary
3) <= 3;ဒီ query လေးမှာဆို လိုချင်တဲ့ column တွေကို အရင် Select လုပ်ထားလိုက်ပြီး Department နဲ့ကတော့ Employee တိုင်းမှာ Department ရှိမှာဖြစ်လို့ Inner Join နဲ့ပဲ joinထားလိုက်ပါတယ်။ where condition လေးမှာတော့ကျွန်တော် sub query လေးရေးထားပါတယ်။ ဒီ sub query လေးကတော့ department လည်းတူရမယ် salary ကလည်း ခုရောက်နေတဲ့ row က salary ရယ်သူ့ထက်ကြီးတာရယ်ရဲ့ count ကို ယူထားလိုက်ပါတယ်။ ဆိုကြပါစို့ လက်ရှိ row မှာ IT Department က salary 85000 ဝင်လာတယ်ဆိုပါစို့(Example input အတိုင်း) ။ 85000 က record 2ခုရှိတော့ count 2ခုဖြစ်မှာစိုးလို့ Distinct လေးထည့်ထားတော့ 85000နဲ့ သူ့ထက်ကြီးတာ 90000ပဲရှိတော့ count က 2 ဖြစ်မယ်။ 2 ကနောက်က စစ်ထားတဲ့အတိုင်း 3ထက်ငယ်တော့ top 3ထဲပါသွားမယ်။ 69000ဆိုရင် သူနဲ့ သူထက်ကြီးတာက 70000,85000,90000ရှိတော့စုစုပေါင်း count က 4ဆိုတော့ 3ထက်ကြီးသွားပြီး top 3ထဲ ပါမပါတော့ဘူးပေါ့။ ဒီ query လေးနဲ့ ကျွန်တော်တို့ရဲ့ Day 5 problem လေးကို solved လုပ်ဖြစ်ခဲ့ပါတယ်ဗျ။

Video လေးကိုတော့ အောက်က YouTube link လေးကနေဝင်ကြည့်လို့ရပါတယ်ဗျာ။ Thank and see you all ပါဗျာ။
30 Days Of LeetCode Database Challenge Day 5 - 185. Department Top Three Salaries (Difficulty Hard)
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 ကို အရင်ဆုံး ဖတ...
