0

我想编写一个查询,该查询将计算某个值在每一行上出现的次数 - 在整个表上我有更多列,我需要计算“9”(例如)在所有列中出现的次数,

在这种情况下,答案是 3:

PlayerName  Nation  Kills   Deaths  SoloKills   PartyKills
666           1      9        0        9            9
4

1 回答 1

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
于 2013-05-17T23:25:33.677 回答