29 ธ.ค. 2563 – เราเริ่มเรียนเวลา 21.00 น. นะครับ ใช้เวลาประมาณ 1.5-2.0 ชั่วโมง ไม่มีพื้นฐานก็เข้าเรียนได้นะครับ : ) แอดสอนด้วย SQLite Online Editor เขียน SQL ผ่านเว็บเบราเซอร์ ไม่ต้องติดตั้งโปรแกรมให้ยุ่งยาก
Contents
SELECT
columnsWHERE
filter dataJOIN
tablesAGGREGATE
functionsGROUP BY
ORDER BY
Google Slides
Example Code
ตัวอย่าง Code ที่เราสอนในคลาสนี้
-- inner join example
SELECT
t1.artistid,
t1.name AS artistName,
t2.title AS albumName,
t3.name AS trackName,
t3.composer,
t4.name AS genreName
FROM artists t1
JOIN albums t2 ON t1.artistid = t2.artistid
JOIN tracks t3 ON t2.albumid = t3.albumid
JOIN genres t4 ON t3.genreid = t4.genreid
WHERE t4.name IN ('Rock', 'Jazz') AND t1.name LIKE 'The%';
-- aggregate function and group by clause
SELECT
t1.name,
COUNT(*) n_songs,
ROUND(AVG(bytes), 4) avg_bytes,
SUM(bytes) sum_bytes,
MIN(bytes) min_bytes,
MAX(bytes) max_bytes
FROM
genres t1
JOIN tracks t2 ON t1.genreid = t2.genreid
GROUP BY t1.name
ORDER BY n_songs DESC
LIMIT 5;
-- answer to homework
SELECT
customers.customerid,
customers.firstname,
customers.lastname,
SUM(invoices.total)
FROM customers, invoices
WHERE customers.customerid = invoices.customerid
GROUP BY 1, 2, 3;
Free SQL Bundle Set 2021
เพื่อนๆสามารถดาวน์โหลดหนังสือ และสมัครเรียนคอร์สออนไลน์ฟรีของเราได้ที่นี่

Leave a Reply