開始使用免費開始

Country 層級小計

你想查看 2004 年三個北歐國家在各國與性別的金牌數。同時你也想要 Country 層級的小計,以取得各國的金牌總數。不過在這個情境下,Gender 層級的小計沒有太大意義,因此請忽略它們。

本練習屬於課程

PostgreSQL 統計摘要與視窗函式

檢視課程

練習說明

  • 依國家與性別統計金牌數。
  • 產生 Country 層級的金牌統計。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- Count the gold medals per country and gender
SELECT
  ___,
  ___,
  COUNT(*) AS Gold_Awards
FROM Summer_Medals
WHERE
  Year = 2004
  AND Medal = 'Gold'
  AND Country IN ('DEN', 'NOR', 'SWE')
-- Generate Country-level subtotals
GROUP BY ___, ___
ORDER BY Country ASC, Gender ASC;
編輯並執行程式碼