分类表选择语句

时间:2013-01-25 14:17:03

标签: mysql sql database select classification

我正在开发一个足球联盟,其中的队伍是由计算机随机完成的。 这个联盟排名球员而不是球队。 每位玩家根据游戏结果得分:

his team wins : player scores 3 point
his team wins >5 goals difference: player scores 4 points
his team draws: player scores 1 point
his team loses: player doesnt score

为了存储联盟数据,我在mySQL InnoDB中创建了这些表:

game (id)
player (num, name)
team (game.id, player.num, type)
goals (time, team.id, team.num, team.type)

type - 标识哪个团队是玩家(CHAR“A”或“B”)

  • 我想根据上面的规则检索分类,我应该如何在mySQL中编写查询?
  • 我避免存储可以计算的数据(良好实践),但是我应该更改表结构吗?

1 个答案:

答案 0 :(得分:0)

SUM(CASE WHEN a THEN 3
         WHEN b THEN 4
         WHEN c THEN 5
         WHEN d THEN 1
                ELSE 0 END) ttl