အားလုံးပဲ မင်္ဂလာပါ။ ဒီနေ့ Day 22 အတွက်ကတော့ Leetcode ရဲ့ difficulties Easy level problem တစ်ပုဒ်ဖြစ်တဲ့ 1148. Article Views I ဆိုတဲ့ problem ကို ရွေးချယ်ထားပါတယ်။ ဒီပုစ္ဆာ မှာတော့ Views table ပေးထားပါတယ်။
1Table: Views2 3+---------------+---------+4| Column Name | Type |5+---------------+---------+6| article_id | int |7| author_id | int |8| viewer_id | int |9| view_date | date |10+---------------+---------+11There is no primary key (column with unique values) for this table, the table may have duplicate rows.12Each row of this table indicates that some viewer viewed an article (written by some author) on some date. 13Note that equal author_id and viewer_id indicate the same person.ကျွန်တော်တို့လုပ်ပေးဖို့လိုတာကတော့ သူရေးထားတဲ့ article ကို ကိုယ်တိုင်အနိမ့်ဆုံး တစ်ကြိမ် ကြည့်ထားတဲ့ author id တွေကိုရှာပေးရမှာပဲဖြစ်ပါတယ်။
1Example 1:2 3Input: 4Views table:5+------------+-----------+-----------+------------+6| article_id | author_id | viewer_id | view_date |7+------------+-----------+-----------+------------+8| 1 | 3 | 5 | 2019-08-01 |9| 1 | 3 | 6 | 2019-08-02 |10| 2 | 7 | 7 | 2019-08-01 |11| 2 | 7 | 6 | 2019-08-02 |12| 4 | 7 | 1 | 2019-07-22 |13| 3 | 4 | 4 | 2019-07-21 |14| 3 | 4 | 4 | 2019-07-21 |15+------------+-----------+-----------+------------+16Output: 17+------+18| id |19+------+20| 4 |21| 7 |22+------+23 ကျွန်တော်ကတော့ အောက်ကအတိုင်း ရေးဖြစ်ခဲ့ပါတယ်။
1**SQL**2 3SELECT DISTINCT author_id AS 'id' FROM Views4WHERE author_id = viewer_id ORDER BY author_id;ဒီ query လေးမှာဆို ကျွန်တော်က author_id နဲ့ viewer_id တူတာကို ရှာထားခြင်းအားဖြင့် သူ့ article ကို ကိုယ်တိုင်ဝင်ကြည့်တဲ့ author_id တွေရလာပြီပဲဖြစ်ပါတယ်။ သူပြောထားတဲ့ order လေးအတိုင်းရအောင် order id ASC နဲ့စီပေးလိုက်ပါတယ်။ ASC ကတော့ default order ဖြစ်လို့မထည့်လည်းရပါတယ်။ ပြီးတော့ author က သူ့ article ကိုတစ်ကြိမ်ထက်ပိုကြည့်ထားရင် author_id ကတစ်ကြိမ်ထက် ပိုပါနေမှာမို့ SELECT လုပ်တဲ့အချိန်မှာ DISTINCT လေးသုံးထားလိုက်ပါဝယ်။ ဒါဆိုရင် လိုချင်တဲ့အဖြေလေးရရှိသွားပြီပဲဖြစ်ပါတယ်ဗျာ။ Video ကိုတော့အောက်က YouTube link လေးကနေတစ်ဆင့်ဝင်ကြည့်နိုင်ပါတယ်ဗျာ။ Stay safe and see you allပါဗျာ။
30 Days Of LeetCode Database Day 22 - 1148. Article Views I
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 ကနေ ခလုတ်လေးတွေ လိုက်နှိပ်ပြီ...


