初學者。所以,我想取一個數據集像如何在case語句中使用子字符串以篩選兩個特定類別並將所有其他類別分組在一個類別中
Id, Name, Team, Games, PPG
1, Joe Smith, Wolves, 5, 14.1
2, Mike Bender, Bears, 6, 7.1
3, Jordan Shoeheart, Blazers, 5, 9.0
4, Sara Eckert, Tigers, 5, 4.1
5, Jason Beard, Bears, 6, 22.1,
6, Noel Redding, Wolves, 4, 1.5
7, Jared Herring, Wolves, 6, 5.5
8, Jennifer Bradley, Bears, 4, 3.2
9, Erica Medley, Tigers, 5, 8.3
10, Justin Awesome, Sharks, 6, 0.3
和回答這個問題,怎麼算爲熊多少實例(記錄),有多少對狼隊,又有多少在TSQL所有其他球隊。我需要使用子字符串,因爲數據有各種格式(有時候開始或結束時會有額外的字符)。我很困惑,因爲我需要與鍵值對,最終會是這個樣子:
Key | Value
-----------------
Wolves | 3
Bears | 3
All Others | 4
我已經試過類似:
SELECT CASE WHEN tbl.team LIKE '%Wolves%' THEN COUNT(tbl.id) end as [Value],
CASE WHEN tbl.team LIKE '%Wolves%' THEN 'Wolves' END AS [Key]
-- this isn't right because I couldn't at least get the values for the others right?
我學習,所以我感謝幫助
當您結束重疊的項目時,例如「茶」和「蒸汽」,事情會變得更有趣。你需要分開單詞進行處理。 – HABO