初学者。所以,我想取一个数据集像如何在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