------解决方案-------------------- select name,count(总胜利),count(总失败),count(总胜利)+count(总失败) as 总局数
(select name,count(result) as 总胜利 from table where result=胜利 group by name
join
select name,count(result) as 总失败 from table where result=失败 group by name
on(...))
大概的这样你测试测试真实SQL
select t1.玩家,胜利局数,失败局数,(胜利局数+失败局数) as 总局数 from
(select 玩家,COUNT(结果) as 胜利局数 from PlayRst where 结果='胜利' group by 玩家)t1
join
(select 玩家,COUNT(结果) as 失败局数 from PlayRst where 结果='失败' group by 玩家)t2
on t1.玩家 = t2.玩家
------解决方案-------------------- select [玩家],
sum(
case [结果] when '胜利' then
1
else
0
end) as [胜利局数],
sum(
case [结果] when '失败' then
1
else
0
end) as [失败局数],
count(1) as [总局数]
From [记录表] Group by [玩家]