1

e.g. Barcelona - Madrid 4:1 or Arsenal - Chelsea 2:0

Which data types are good to represent 4:1 and 2:0 etc?

The options that come to mind are:

  1. Two smallints
  2. One decimal (i.e. 4.1 and 2.0)
  3. One point (i.e. 4,1 and 2,0)

Anything else? How'd you do it? It must be easy to retrieve who's won the game and what the difference in goals was, which makes me tend to the first option but maybe there is more (memory considerations...)?

4

1 回答 1

2

最好将分数存储为两个单独的值。您建议的不同选项之间的内存和时间差异太小而无法关心,除非您的数据库非常庞大。两个单独的值将使编写查询更容易,而无需包含在每个查询中解析出两个值的逻辑。

此外,如果您愿意,您还可以为点差、获胜者等添加额外的列。在表中保留更多数据会导致更慢的更新/插入,但更简单和更快的读取查询(因为已经计算了获胜者和传播)。假设这是针对体育网站或类似网站的,那么在给定的一天,您的阅读量(即网站的访问者)可能比插入/更新(玩过的新游戏)要多得多。

于 2012-06-25T22:50:13.823 回答