အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 10 အတွက်ကတော့ Leetcode ရဲ့ difficulties Easy level problem တစ်ပုဒ်ဖြစ်တဲ့ 627. Swap Sex of Employees ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ အတွက်ကတော့ ကျွန်တော်တို့ကို Salary ဆိုတဲ့ table လေးတစ်လုပေးထားပါတယ်။ Employee နဲ့ပါတ်သက်တဲ့ information တွေပါပြီး အဓိကက တော့ sex ဆိုတဲ့ column လေးပဲဖြစ်ပါတယ်။ Enum value ဖြစ်ပြီး ယောကျာ်းလေးဆို 'm' နဲ့မိန်းကလေးဆို 'f'ဆိုပြီး value ရှိမှာဖြစ်ပါတယ်။
1Example 1:
2
3Input:
4Salary table:
5+----+------+-----+--------+
6| id | name | sex | salary |
7+----+------+-----+--------+
8| 1 | A | m | 2500 |
9| 2 | B | f | 1500 |
10| 3 | C | m | 5500 |
11| 4 | D | f | 500 |
12+----+------+-----+--------+
13Output:
14+----+------+-----+--------+
15| id | name | sex | salary |
16+----+------+-----+--------+
17| 1 | A | f | 2500 |
18| 2 | B | m | 1500 |
19| 3 | C | f | 5500 |
20| 4 | D | m | 500 |
21+----+------+-----+--------+
22
23*Explanation: *
24
25(1, A) and (3, C) were changed from 'm' to 'f'.
26(2, B) and (4, D) were changed from 'f' to 'm'.
27 ဒီ problem လေးမှာ ကျွန်တော်တို့လုပ်ပေးဖို့လိုအပ်တာကတော့ 'm' နဲ့ 'f' ကို switch လုပ်ဖို့ update query လေးတစ်ကြောင်းရေးပေးရမှာဖြစ်ပါတယ်။ ကျွန်တော်ကတော့ အောက်ကအတိုင်း SQL လေးရေးဖြစ်ခဲ့ပါတယ်။
1
2UPDATE Salary SET sex = CASE
3 WHEN sex = 'm' THEN 'f'
4 WHEN sex = 'f' THEN 'm'
5 END;ဒီမှာဆိုရင် ကျွန်တော်တို့ update လုပ်မှာက sex column ဖြစ်လို့ set ရဲ့နောက်မှာရေးပြီး Case လေးကိုပဲအသုံးပြုထားပါတယ်။ sex value က 'm' ဖြစ်ရင် 'f' ပြောင်းပြီး 'f' ဖြစ်ရင် 'm' ပြောင်းပေးလိုက်တာပဲဖြစ်ပါတယ်။ ဒါဆိုရင်တော့ ဒီ problem လေးကပြေလည်သွားခဲ့ပြီပဲဖြစ်ပါတယ်ဗျာ။ Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Challenge Day 10 - (627. Swap Sex of Employees)
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 ကို အရင်ဆုံး ဖတ...

