34,873
社区成员
发帖
与我相关
我的任务
分享select distinct name from tb order by nameselect distinct name ,other from tb order by nameselect t.* from main_table t where id = (select min(id) from main_table where name = name) order by t.nameselect t.* from main_table t where id = (select max(id) from main_table where name = name) order by t.name楼主看一下,也许对你有用!
create table tb(id int, name varchar(10), other varchar(10))
insert into tb
select 1, 'aa','00' union all
select 2, 'bb','00' union all
select 3, 'cc','00' union all
select 4, 'aa','00' union all
select 5, 'dd','00' union all
select 6, 'ee','00'
select * from tb a where not exists (select 1 from tb where name=a.name and id<a.id)
/*
id name other
-------------------------
1 aa 00
2 bb 00
3 cc 00
5 dd 00
6 ee 00
*/
drop table tb
SELECT NAME ,OTHER FROM # GROUP BY NAME,OTHER ORDER BY NAME , OTHER
SELECT NAME ,Max(OTHER) FROM # GROUP BY NAMEORDER BY NAME
select distinct name from table1
或
select name from table1 group by nameselect distinct name from main_table