昨天我开始使用一些新的colomns更新我的记分牌并在这里得到一些好的提示,所以我可以大胆地提出另一个问题吗?
简单的SQL在这里,但我需要将Case()作为欧元汇总,以便显示在所有轮次中获得或损失的总欧元。
SELECT t1.playerid, sum(t1.points) as totalpoints, count(t1.playerid) as rounds,avg(points) as avgpoints
,Case
when count(t1.playerid) in(7,6) and (select points from pokermax_scores as t4 where t1.playerid=t4.playerid and t1.tournamentid=t4.tournamentid) = 38 then 15
when count(t1.playerid) in(7,6,5) and (select points from pokermax_scores as t4 where t1.playerid=t4.playerid and t1.tournamentid=t4.tournamentid) = 25 then 5
when count(t1.playerid) in(5,4) and (select points from pokermax_scores as t4 where t1.playerid=t4.playerid and t1.tournamentid=t4.tournamentid) = 38 then 10
when count(t1.playerid) = 7 and (select points from pokermax_scores as t4 where t1.playerid=t4.playerid and t1.tournamentid=t4.tournamentid) = 16 then 0
when count(t1.playerid) = 4 and (select points from pokermax_scores as t4 where t1.playerid=t4.playerid and t1.tournamentid=t4.tournamentid) = 25 then 0
else -5
End as Euro
FROM pokermax_scores as t1
group by t1.playerid
order by avgpoints desc
返回: img“http://i62.tinypic.com/213iud0.png”
正如你所看到的那样,欧元并非总结,而只是随机的......
答案 0 :(得分:0)
这是解决方案,首先创建一个子查询,收集所有信息raw,然后在主查询中汇总这个sum()。
示例:
select t3.playerid,sum(t3.Euro)
from
(
select t2.playerid,t2.points,t2.tournamentid,
Case
when count(t1.playerid) in(7,6) and t2.points = 38 then 15
when count(t1.playerid) in(7,6,5) and t2.points = 25 then 5
when count(t1.playerid) in(5,4) and t2.points = 38 then 10
when count(t1.playerid) = 7 and t2.points = 16 then 0
when count(t1.playerid) = 4 and t2.points = 25 then 0
else -5
End as Euro
FROM pokermax_scores as t1, pokermax_scores as t2
where t1.tournamentid = t2.tournamentid
group by t2.tournamentid, t2.playerid) as t3
group by t3.playerid