အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 9 အတွက်ကတော့ Leetcode ရဲ့ difficulties Medium level problem တစ်ပုဒ်ဖြစ်တဲ့ 176. Second Highest Salary ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ Employee table တစ်ခုထဲပဲပေးထားပါတယ်။ ဒီ table မှာဆို id နဲ့ salary ဆိုပြီး column နှစ်ခုပေးထားပါတယ်။
1*Example 1:*
2
3Input:
4Employee table:
5+----+--------+
6| id | salary |
7+----+--------+
8| 1 | 100 |
9| 2 | 200 |
10| 3 | 300 |
11+----+--------+
12Output:
13+---------------------+
14| SecondHighestSalary |
15+---------------------+
16| 200 |
17+---------------------+
18
19*Example 2:*
20
21Input:
22Employee table:
23+----+--------+
24| id | salary |
25+----+--------+
26| 1 | 100 |
27+----+--------+
28Output:
29+---------------------+
30| SecondHighestSalary |
31+---------------------+
32| null |
33+---------------------+
34 ကျွန်တော်တို့ က ဒုတိယမြောက် လစာအများဆုံး Employee ကိုရှာပေးရမှာပဲဖြစ်ပါတယ်။ မရှိရင်တော့ null vale ပြန်ပေးရမှာပဲဖြစ်ပါတယ်။
1
2SELECT MAX(e.salary) AS 'SecondHighestSalary' FROM Employee e
3WHERE e.salary < (
4 SELECT MAX(e2.salary) FROM Employee e2
5);ဒီမှာဆို ကျွန်တော်တို့ sub query လေးကို အရင်ကြည့်ရအောင်။ sub query က table ထဲမှာရှိတဲ့ maximum salaryကိုယူထားတာပဲဖြစ်တယ်။ ကျွန်တော်တို့ input value က 100, 200, 300 ရှိတယ်ဆိုပါစို့။ အမြင့်ဆုံးကို sub query က ယူလိုက်တော့ 300 ဖြစ်မယ်။ main query က နေ ကျန်တဲ့ထဲက အမြင်ဆုံးကိုယူလိုက်တော့ 200။ condition အရ 300က အမြင့်ဆုံး သူ့ထက် ငယ်တဲ့ အမြင့်ဆုံးတန်ဖိုးက ဒုတိယမြောက်အမြင့်ဆုံဆိုတော့ 200ရသွားတာပေါ့။ မရှိရင်တော့ Null value ပြန်မှာပဲဖြစ်ပါတယ်
1First Max Record From Sub Query - 300
2Second Max Record From Main Query - 200
3200 < 300 => Second Hightest Salaryဒါဆို Day 9 အတွက်လလည်းအဆင်ပြေသွားခဲ့ပြီပဲဖြစ်ပါတယ်ဗျာ။ Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Challenge Day 9 - (76. Second Highest Salary)
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 ကို အရင်ဆုံး ဖတ...

