我有两张桌子:
CREATE TABLE `fl_poll` (
`id_poll` int(11) NOT NULL AUTO_INCREMENT,
`id_player` int(11) NOT NULL,
`position` varchar(50) NOT NULL,
`score` int(11) NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`ip` varchar(100) NOT NULL,
PRIMARY KEY (`id_anketa`)
) ENGINE=MyISAM;
CREATE TABLE `fl_player` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`id_team` int(11) NOT NULL,
`name` varchar(100) NOT NULL,
`lastname` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;
我想问一下,是否有任何解决方案如何从表 fl_player 中选择所有玩家,计算他们的分数并按得分最高的前 3 名玩家排序,而其他人将按照他们的姓氏排序?例如我有六个玩家:
表 fl_player:
id | lastname
------------------------
1 Smith
2 Johnson
3 Todd
4 Dragon
5 Bond
6 Black
表 fl_poll:
+-----------+-------+
| id_player | score |
+-----------+-------+
| 1 | 2 |
| 2 | 4 |
| 3 | 6 |
| 4 | 8 |
| 5 | 10 |
| 6 | 12 |
+-----------+-------+
我希望这样的结果:
+-----------+----------------------------------------+
| id_player | lastname |
+-----------+----------------------------------------+
| 6 | Black <-- top 3 with highest score |
| 5 | Bond |
| 4 | Dragon |
| 2 | Johnson <-- from now order by lastname |
| 1 | Smith |
| 3 | Todd |
+-----------+----------------------------------------+