mysql获取分组后每组的最大值实例详解
1. 测试数据库表如下:
create table test
(
`id` int not null auto_increment,
`name` varchar(20) not null default '',
`score` int not null default 0,
primary key(`id`)
)engine=InnoDB CHARSET=UTF8;
2. 插入如下数据:
mysql> select * from test;
+----+----------+-------+
| id | name | score |
+----+----------+-------+
| 1 | jason | 1 |
| 2 | jason | 2 |
| 3 | jason | 3 |
| 4 | linjie | 1 |
| 5 | linjie | 2 |
| 6 | linjie | 3 |
| 7 | xiaodeng | 1 |
| 8 | xiaodeng | 2 |
| 9 | xiaodeng | 3 |
| 10 | hust | 2 |
| 11 | hust | 3 |
| 12 | hust | 1 |
| 13 | haha | 1 |
| 14 | haha | 2 |
| 15 | dengzi | 3 |
| 16