scene one:
A field of sport shooting, John Doe, Wang Wu three people participate in the competition.
Shooting rules of the game: a total of three games; after the end of three rounds, the best score to take rank as a personal best.
Design database tables:
CREATE TABLE `TEST` ( `ID` int(11) NOT NULL, `NAME` varchar(45) DEFAULT NULL COMMENT '名称', `SCORE` int(11) DEFAULT NULL COMMENT '分数', `ROUND` int(11) DEFAULT NULL COMMENT '回合', PRIMARY KEY (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
Inserting data:
three score down
Zhang 9,10,10 respectively;
John Doe 10,9,8 respectively;
King five are 9,8,8;
After sorting by known, to take the data to each data ID is 4,2,3
By grouping names, names and get the best results created
It leads to the following table associated with the query results
At this time, the results need to be removed and the packet ID for each group the minimum value
The ID of the query and sort out
This is taken out in the same table each optimization data.
Should coupled with a condition, when the last two data points the same, the higher the average score of ranking, the same is sorted by name.