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

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 ကနေ ခလုတ်လေးတွေ လိုက်နှိပ်ပြီ...

