mysql中,这条语句如何写呢

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

mysql中,这条语句如何写呢

相关文章:

你感兴趣的文章:

标签云: