အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 4 အတွက်ကတော့ Leetcode ရဲ့ difficulties medium problem တစ်ပုဒ်ဖြစ်တဲ့ 178. Rank Scores ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ Score ဆိုတဲ့ table လေးတစ်ခုပဲပေးထားပါတယ်။ လိုချင်တာကတော့ score များရာကနေ order စီပေးပြီး score အလိုက် Rank ခွဲပေးရမှာပါ။ score တူနေရင် Rank ကလည်းတူတူပဲဖြစ်ရမယ်ဆိုပြီးပြောထားပါတယ်။
အဲ့တော့ SQL လေးရေးလိုက်ကြရအောင်ဗျာ။
1SELECT s.score, (
2 SELECT COUNT(DISTINCT ssub.score) FROM Scores ssub where ssub.score >= s.score
3) AS 'rank' FROM Scores s ORDER BY s.score DESC;ဒီမှာဆို လိုချင်တဲ့ output အတိုင်း score နဲ့ rank ကို ဆွဲထုတ်ပြီး order ကို desc စီပေးထားပါတယ်။ ဒီနေရာမှာ rank ကို '' ထဲထားရတာက mysql မှာ rank ဆိုတဲ့ keyword ပါနေတော့ မထည့်ထားရင် error တက်နေမှာပဲဖြစ်ပါတယ်။ rank အနေနဲ့ကတော့ ကျွန်တော် sub query လေးရေးထားပါတယ်။ Count function နဲ့ Distinct keyword လေးကိုလည်းသုံးထားပါတယ်။ ရည်ရွယ်ချက်ကတော့ လက်ရှိရောက်နေတဲ့ score ရယ်သူ့ထက်မြင့်တာတွေရယ်ကို rank အနေနဲ့ယူချင်လို့ပါ။
ဆိုကြပါစို့ ကျွန်တော်တို့ score table မှာ score (4,4,3,2,2) ရှိတယ်ဆိုပါစို့။
ပထမဦးဆုံးအနေနဲ့က 4 query အရဆို 4နဲ့ လေးထက်ကြီးတာ ရဲ့ count အရေအတွက်ဖြစ်ရမယ်။ table ထဲမှာ တူညီတဲ့ 4ကနှစ်ခုပါနေတော့ Distinct မထားထားရင် rank က2ဖြစ်နေမှာပါ။ Distinct ထည့်ထားတော့ 4 နဲ့ သူ့အထက်ဆိုတော့ လေးထက်ကြီးတာမရှိတော့ rank က 1ပဲဖြစ်နေမှာပါ။ 3ဆိုလည်း 3နဲ့ 3ထက်ကြီးတာဆိုတေယ့ 3နဲ့4 နှစ်ခုရှိတော့ rank က 2 ဖြစ်နေမှာပါ။ 2 အတွက်ဆို rank က 3ပေါ့။ ဒါဆိုကျွန်တော်တို့လိုချင်တဲ့အတိုင်း output လေးရရှိလာမှာပဲဖြစ်ပါတယ်။ Day4 အတွက်လည်းပြီးဆုံးသွားပြီဆိုတော့ ကိုဖြေထားတဲ့ မတူညီတဲ့ပုံစံလေးတွေရှိရင်လည်း comment မှာပြောပြသွားလို့ရပါတယ်ဗျ။ Video လေးကိုတော့ အောက်က YouTube link လေးကနေဝင်ကြည့်လို့ရပါတယ်ဗျာ။ see you all ပါဗျာ။
30 Days Of LeetCode Database Challenge Day 4 - 178. Rank Scores
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 2 - GitHub Actions ရဲ့ အဓိက Concepts များနှင့် Runner အကြောင်း
ပြီးခဲ့တဲ့အပတ် Day 1 တုန်းက ကျွန်တော်တို့ CI/CD ရဲ့ Concept တွေကို အကြမ်းဖျင်း ပြောခဲ့ကြပြီးပြီနော်။ ဒီနေရာမှာ လက်တွေ့မစ...
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 တိုင်း စဉ်းစားဖူးကြမှာပါ။ ဈေးကွက်အခြေအနေ...

