日期:2014-05-16  浏览次数:20714 次

mysql中,这条语句怎么写呢?
id leixing
1 a
2 b
3 c
4 d
5 a
6 a
每个leixing,我只想要一条记录,并且是id最大哪一条,sql语句怎么写呢?


------解决方案--------------------
drop table if exists table1;
create table table1(id int(11),leixing char(1),primary key (id));
insert into table1 values(1, 'a '),(2, 'b '),(3, 'c '),(4, 'd '),(5, 'a '),(6, 'a ');
select max(id),leixing from table1 group by leixing

===============

query result(4 records)
max(id) leixing
6 a
2 b
3 c
4 d