အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ 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

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


