ปรับแต่งผลลัพธ์ให้เรียบร้อย
กลับมาที่การสรุปรางวัลในกลุ่มประเทศสแกนดิเนเวียที่เคยสร้างไว้ก่อนหน้านี้ คราวนี้จะทำให้ผลลัพธ์ดูดียิ่งขึ้น โดยแทนที่ค่า null ด้วยข้อความที่มีความหมาย
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
PostgreSQL Summary Stats and Window Functions
คำแนะนำการฝึกหัด
- แทนที่ค่า
nullในคอลัมน์Countryด้วยAll countriesและค่าnullในคอลัมน์Genderด้วยAll genders
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
SELECT
-- Replace the nulls in the columns with meaningful text
___(Country, ___) AS Country,
___(Gender, ___) AS Gender,
COUNT(*) AS Awards
FROM Summer_Medals
WHERE
Year = 2004
AND Medal = 'Gold'
AND Country IN ('DEN', 'NOR', 'SWE')
GROUP BY ROLLUP(Country, Gender)
ORDER BY Country ASC, Gender ASC;