အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 11 အတွက်ကတော့ Leetcode ရဲ့ difficulties Medium level problem တစ်ပုဒ်ဖြစ်တဲ့ 1045. Customers Who Bought All Products ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ ကျွန်တော်တို့ကို Customer နဲ့ Product table နှစ်ခု ပေးထားပါတယ်။ Customer table ထဲမှာတော့ customer_id နဲ့ product_key ကတော့ foreign key column အနေနဲ့ Product table ထဲက column ကို reference လုပ်ထားပါတယ်။ Product table ထဲမှာတော့ product_key တစ်ခုပဲရှိပါတယ်။
1***Example 1:***
2
3Input:
4Customer table:
5+-------------+-------------+
6| customer_id | product_key |
7+-------------+-------------+
8| 1 | 5 |
9| 2 | 6 |
10| 3 | 5 |
11| 3 | 6 |
12| 1 | 6 |
13+-------------+-------------+
14Product table:
15+-------------+
16| product_key |
17+-------------+
18| 5 |
19| 6 |
20+-------------+
21Output:
22+-------------+
23| customer_id |
24+-------------+
25| 1 |
26| 3 |
27+-------------+
28***Explanation: ***
29The customers who bought all the products (5 and 6) are customers with IDs 1 and 3.
30 ကျွန်တော်တို့ လိုချင်တဲ့ result ကတော့ Example ကအတိုင်း Product table ထဲမှာရှိတဲ့ product အကုန်လုံးကိုဝယ်တဲ့ customer IDs တွေကို ရှာပေးရမှာပဲဖြစ်ပါတယ်။ ကျွန်တော်ကတော့ အောက်ကအတိုင်း query လေးရေးဖြစ်ခဲ့ပါတယ်။
1SELECT c.customer_id FROM Customer c GROUP BY c.customer_id
2HAVING COUNT(DISTINCT c.product_key) = (SELECT COUNT(p.product_key) FROM Product p);အရင်ဆုံး ကျွန်တော် customer_id နဲ့ grouping လုပ်လိုက်ပါတယ်။ (Please Refrence Example Table) Customer တစ်ယောက်ချင်းစီ တွက်ချင်လို့ပဲဖြစ်ပါတယ်။ ဆိုကြပါစို့ ကျွန်တော်တို့မှာ customer 1 ကို group လုပ်လိုက်ရင် customer 1နဲ့ဆိုင်တဲ့ product key က 5, 6 ရှိနေမှာပါ။ ဒီနေရာမှာ customer ထဲက product_key ရဲ့ count ကို ယူလိုက်ချင်းအားဖြင့် customer ဝယ်ထားတဲ့ product အရေအတွက်ရမှာပဲဖြစ်ပါတယ်။ ကျွန်တော် Distinct သုံးတာကတော့ customer တစ်ယောက်က တူညီတဲ့ product တွေကိုဝယ်နိုင်လို့ပဲဖြစ်ပါတယ်။ distinct ထည့်လိုက်ခြင်းအားဖြင့်တူရင် တစ်ခုပဲယူဆလိုက်တာပေါ့။
ရလာတဲ့ result ကို Product table ထဲမှာရှိတဲ့ product တွေရဲ့ အရေအတွက်နဲ့ နှိုင်းယှဉ်လို့ ညီတယ်ဆိုရင် customer က product အကုန်ဝယ်ထားတဲ့ customer လို့ ယူဆနိုင်တာပဲဖြစ်ပါတယ်။ ဒါဆို Day 11 အတွက်လည်း အဆင်ပြေသွားခဲ့ပါပြီဗျာ။
Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Day 11 - 1045. Customers Who Bought All Products)
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 ကို အရင်ဆုံး ဖတ...

