အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 12 အတွက်ကတော့ Leetcode ရဲ့ difficulties Easy level problem တစ်ပုဒ်ဖြစ်တဲ့ 596. Classes With at Least 5 Students ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ ကျွန်တော်တို့ကို **Courses ** table လေးပေးထားပါတယ်။
1***Example 1:***
2
3Input:
4Courses table:
5+---------+----------+
6| student | class |
7+---------+----------+
8| A | Math |
9| B | English |
10| C | Math |
11| D | Biology |
12| E | Math |
13| F | Computer |
14| G | Math |
15| H | Math |
16| I | Math |
17+---------+----------+
18Output:
19+---------+
20| class |
21+---------+
22| Math |
23+---------+
24
25
26***Explanation: ***
27- Math has 6 students, so we include it.
28- English has 1 student, so we do not include it.
29- Biology has 1 student, so we do not include it.
30- Computer has 1 student, so we do not include it.
31 ဒီ table လေးမှာဆိုရင် student နဲ့ class ဆိုတဲ့ column နှစ်ခုပေးထားပြီး ဒီ column နှစ်ခုပေါင်းက primary key ဖြစ်နေပါတယ်။ ကျွန်တော်တို့ ရှာပေးရမှာကတော့ student အနိမ့်ဆုံး ငါးယောက်နဲ့ အထက်ရှိတဲ့ class တွေကို ရှာပေးရမှာပဲဖြစ်ပါတယ်။
ကျွန်တော်ကတော့ အောက်က အတိုင်း query လေးရေးဖြစ်ခဲ့ပါတယ်။
1SELECT class FROM Courses
2GROUP BY class
3HAVING COUNT(student) >= 5;ပထမဆုံး အနေနဲ့ကျွန်တော်က class တစ်ခုချင်းစီရဲ့ record နဲ့တွက်ချင်တော့ Group By ကို class column လေးနဲ့လုပ်လိုက်ပါတယ်။ ဒါဆို ကျွန်တော်တို့ class တစ်ခုချင်းစီရဲ့ record ရလာခဲ့ပြီ။ ဒီထဲမှာရှိတဲ့ student အရေအတွက်ကိုသိချင်တော့ COUNT Function လေးနဲ့ ယူလိုက်ပြီး ရလာတဲ့ student အရေအတွက်ဟာ အနိမ့်ဆုံးငါးယောက်နဲ့ အထက်ရှိရမယ်ဆိုပြီး condition လေးစစ်ထားပေးလိုက်ပါတယ်။ ဒါဆို ကျွန်တော်တို့လိုချင်တဲ့ student ငါးယောက်နဲ့အထက်ရှိတဲ့ class တွေရလာပြီပဲဖြစ်ပါတယ်ဗျာ။
Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Day 12 - 596. Classes With at Least 5 Students
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 ကနေ ခလုတ်လေးတွေ လိုက်နှိပ်ပြီ...


