如何从mysql表中为足球赛结果设置表格的游戏限制?

时间:2012-06-04 11:00:52

标签: mysql

如何限制每个俱乐部的比赛数量,我希望每个俱乐部只有10场比赛。 这是我在这里找到的所有游戏的代码how to output a standings table on the fly from a mysql table of football [soccer] results?

select 
team, 
count(*) played, 
count(case when goalsfor > goalsagainst then 1 end) wins, 
count(case when goalsagainst> goalsfor then 1 end) lost, 
count(case when goalsfor = goalsagainst then 1 end) draws, 
sum(goalsfor) goalsfor, 
sum(goalsagainst) goalsagainst, 
sum(goalsfor) - sum(goalsagainst) goal_diff,
sum(
      case when goalsfor > goalsagainst then 3 else 0 end 
    + case when goalsfor = goalsagainst then 1 else 0 end
) score 
from (
select hometeam team, goalsfor, goalsagainst from scores 
union all
select awayteam, goalsagainst, goalsfor from scores
) a 
group by team
order by score desc, goal_diff desc;

1 个答案:

答案 0 :(得分:0)

使用SELECT中的LIMIT子句返回有限数量的行 文档:http://dev.mysql.com/doc/refman/5.5/en/select.html