အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 16 အတွက်ကတော့ Leetcode ရဲ့ difficulties Medium level problem တစ်ပုဒ်ဖြစ်တဲ့ 1070. Product Sales Analysis III ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ Sales ဆိုတဲ့ table လေးပေးထားပါတယ်။ ဒီ table ထဲမှာဆို sale_id, product_id, year, quantity, price ဆိုတဲ့ column လေးတွေပေးထားပါတယ်။
1Example 1:
2
3Input:
4Sales table:
5+---------+------------+------+----------+-------+
6| sale_id | product_id | year | quantity | price |
7+---------+------------+------+----------+-------+
8| 1 | 100 | 2008 | 10 | 5000 |
9| 2 | 100 | 2009 | 12 | 5000 |
10| 7 | 200 | 2011 | 15 | 9000 |
11+---------+------------+------+----------+-------+
12
13Output:
14+------------+------------+----------+-------+
15| product_id | first_year | quantity | price |
16+------------+------------+----------+-------+
17| 100 | 2008 | 10 | 5000 |
18| 200 | 2011 | 15 | 9000 |
19+------------+------------+----------+-------+
20 ကျွန်တော်တို့ လုပ်ပေးရမှာကတော့ product တွေမှာ ရောင်းတဲ့ နှစ်တွေအများကြီးရှိတာမို့ product တစ်ခုချင်းစီအတွက် အစောဆုံးနှစ်မှာရောင်းခဲ့တဲ့ data တွေကို ရှာပေးရမှာပဲဖြစ်ပါတယ်။
ကျွန်တော်ကတော့ အောက်က query လေးအတိုင်းရေးဖြစ်ခဲ့ပါတယ်။
1SELECT product_id,
2year AS first_year,
3quantity,
4price FROM Sales
5WHERE (product_id, year) IN (
6 SELECT product_id, MIN(year) FROM Sales
7GROUP BY product_id
8);ဒီ မှာဆို အရင်ဆုံးsub query လေးမှာ ကျွန်တော်ကတော့ product တစ်ခုချင်းစီအတွက် record ရအောင် product id နဲ့ Group By လုပ်လိုက်ပါတယ်။ အဲ့ ရလာတဲ့ product data ထဲကမှ အစောဆုံး နှစ်ကိုရအောင် MIN Function သုံးပြီးအငယ်ဆုံးနှစ်ရယ် အဲ့ နှစ်မှာရောင်းခဲ့တဲ့ product id တွေရယ်ကို ရှာလိုက်ပါတယ်။ Main query ကြီးမှာတော့ sub query ကရလာတဲ့ product IDs တွေရယ် year ရယ်တူနေတဲ့ record တွေကို ရှာဖို့ where condition မှာစစ်ပေးလိုက်ပါတယ်။ ဒါဆိုကျွန်တော်တို့လိုချင်တဲ့ product တစ်ခုချင်းစီဖို့ အစောဆုံးနှစ် ရောင်းခဲ့တဲ့ data တွေရရှိပြီပဲဖြစ်ပါတယ်ခင်ဗျာ။ Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Day 16 - 1070. Product Sales Analysis III
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 တိုင်း စဉ်းစားဖူးကြမှာပါ။ ဈေးကွက်အခြေအနေ...

