我想编写一个查询,计算每行显示某个值的次数 - 在整个表格中我有更多的列,我需要计算所有的“9”(例如)出现的次数列,
在这种情况下,答案是3:
PlayerName Nation Kills Deaths SoloKills PartyKills
666 1 9 0 9 9
答案 0 :(得分:2)
select PlayerName
, sum(case when Nation = 9 then 1 else 0 end +
case when Kills = 9 then 1 else 0 end +
case when Deaths = 9 then 1 else 0 end +
...
) as SumOfNines
from YourTable
group by
PlayerName