加入註解——NBA 有多少位紐西蘭球員?
你和朋友想知道有多少位紐西蘭人(暱稱 Kiwis)在 NBA 打球。你的朋友試著寫了一個查詢,但格式不好,還有好幾個錯誤。你重新撰寫了查詢,不過你想保留他的原始版本,方便比較與日後參考。
這個練習要你建立單行註解,並把一段程式碼區塊註解掉。
本練習屬於課程
改進 SQL Server 中的查詢效能
練習說明
- 在第 2 行加入單行註解:
First attempt, contains errors and inconsistent formatting。 - 在第 3 行與第 11 行,將你朋友的查詢以區塊註解標註起來。
- 在第 14 行加入單行註解:
Second attempt - errors corrected and formatting fixed。 - 移除第 15 行到第 23 行你自己的查詢上的區塊註解語法。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Your friend's query
select PlayerName, p.Country,sum(ps.TotalPoints)
AS TotalPoints
FROM PlayerStats ps inner join Players On ps.PlayerName = p.PlayerName
WHERE p.Country = 'New Zeeland'
Group
by PlayerName, Country
order by Country;
-- Your query
/*
SELECT p.PlayerName, p.Country,
SUM(ps.TotalPoints) AS TotalPoints
FROM PlayerStats ps
INNER JOIN Players p
ON ps.PlayerName = p.PlayerName
WHERE p.Country = 'New Zealand'
GROUP BY p.PlayerName, p.Country;
*/