Thuta Learning
ရှာဖွေရန်
ExercisesData & Databasesbeginner

Practice Set 1: SELECT & Filtering

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Practice Set 1: SELECT & Filtering ကို ကိုယ်တိုင် လေ့ကျင့်ကြည့်မယ်
  • သင်ခဲ့ပြီးသား skill တွေကို practice လုပ်ပြီး ခိုင်မာအောင်လုပ်မယ်
  • အမှားရှာ၊ ပြင်တတ်၊ ကိုယ်တိုင် check လုပ်တတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ lesson က basic-level query တွေဖြစ်တဲ့ SELECT, WHERE, ORDER BY, LIKE, DISTINCT ကို ပြန်လည်ကျင့်သားရအောင် ရည်ရွယ်ထားတဲ့ practice set ဖြစ်ပါတယ်။ Theory အသစ်ဘာမှမပါဘဲ ခုနက Bookstore project မှာသုံးခဲ့တဲ့ Books, Customers table တွေကို base ယူပြီး task အသေးလေးတွေနဲ့ hands-on ကျင့်ကြည့်ရမှာဖြစ်ပါတယ်။ Query ရေးရင်း filter condition, sort order, pattern matching တွေကို ကိုယ်ပိုင် reflex ဖြစ်လာအောင် လေ့ကျင့်ဖို့ အရေးကြီးပါတယ်။ Task တစ်ခုစီကို ကိုယ်တိုင် query ရေးကြည့်ပြီးမှ code block ထဲက sample answer ကို ပြန်ကြည့်ပါ။

လေ့ကျင့်ခန်းများ

Task 1: Books table ထဲက Price 10000 ထက်ကြီးတဲ့ book title နဲ့ price ကို SELECT + WHERE နဲ့ ထုတ်ပါ။ Task 2: Customers table ထဲက City column ရဲ့ ထပ်နေတဲ့ value မပါဘဲ unique city list ကို SELECT DISTINCT နဲ့ ထုတ်ပါ။ Task 3: Books table ထဲက Title အနေနဲ့ 'a' စာလုံးနဲ့ 'e' စာလုံးပါတဲ့ book တွေကို LIKE သုံးပြီး ရှာပါ (title ထဲ 'a' ပါတဲ့စာအုပ်တွေရှာဖို့ '%a%' သုံးပါ)။ Task 4: Books table အကုန်လုံးကို Price ကြီးစဉ်ငယ်လိုက် (highest first) ORDER BY DESC နဲ့ sort လုပ်ပြပါ။

Code နမူနာ

sql
-- Task 1: Books over 10000 in price
SELECT Title, Price FROM Books WHERE Price > 10000;

-- Task 2: Unique cities
SELECT DISTINCT City FROM Customers;

-- Task 3: Titles containing 'a'
SELECT Title FROM Books WHERE Title LIKE '%a%';

-- Task 4: Books sorted by price, highest first
SELECT Title, Price FROM Books ORDER BY Price DESC;
You should see
Task 4 ခုစလုံးအတွက် query result table ငယ်လေးတစ်ခုစီ ပေါ်လာပြီး filter, distinct, pattern match, sort order မှန်ကန်မှုကို ကိုယ်တိုင် စစ်ဆေးနိုင်ပါလိမ့်မယ်။

၅ မိနစ် စမ်းကြည့်

Task 1 ရဲ့ condition ကို Price > 10000 AND Stock > 0 လို့ ပြောင်းပြီး AND operator ပေါင်းထည့်ကြည့်ပါ - 5 minutes အတွင်း စမ်းကြည့်ပါ။

သတိလေးတစ်ချက်

Query ရေးပြီးတိုင်း run ခင် condition ကို တစ်ခေါက်ပြန်ဖတ်ပါ - filter condition လွဲရင် result set က ကွာဟသွားနိုင်ပေမယ့် error တစ်ခုမှ မပြတတ်ပါဘူး။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • LIKE pattern ရေးတဲ့အခါ % (percent sign) ကို မှားပြီး _ (underscore) နဲ့ ရောသုံးမိတတ်တာ
  • ORDER BY မှာ DESC ထည့်ဖို့ မေ့ပြီး default ASC (ငယ်စဉ်ကြီးလိုက်) ရလာတာကို 'sort မလုပ်ဘူး' လို့ထင်မိတတ်တာ

အခု ကိုယ်တိုင် စမ်းကြည့်

Task 1 ရဲ့ condition ကို Price > 10000 AND Stock > 0 လို့ ပြောင်းပြီး AND operator ပေါင်းထည့်ကြည့်ပါ - 5 minutes အတွင်း စမ်းကြည့်ပါ။

You'll know it worked when: Task 4 ခုစလုံးအတွက် query result table ငယ်လေးတစ်ခုစီ ပေါ်လာပြီး filter, distinct, pattern match, sort order မှန်ကန်မှုကို ကိုယ်တိုင် စစ်ဆေးနိုင်ပါလိမ့်မယ်။

Practice Set 1: SELECT & Filtering | Thuta Learning