SQL选择查询排序值

时间:2015-09-13 22:50:55

标签: mysql sql

好的我现在有一张名为Game的桌子

Player     Score      TimesPlayed
  1         900           5
  2         500           3
  3         350           2
  4         600           4

我需要一个Query来返回得分乘以每个Player按降序排序的TimesPlayed数。所以我需要这个作为输出

4500 - Player 1
2400 - Player 4
1500 - Player 2
700  - Player 3

我写过这篇文章,但不知道它是不是正确的方法。

SELECT Score, Player, TimesPlayed FROM Game ORDER BY Score DESC

1 个答案:

答案 0 :(得分:0)

如果你想要得分乘以,你需要乘以......

SELECT Player, Score * TimesPlayed as total_score FROM Game ORDER BY total_score DESC