求语句 去除重复并排序

wzllin 2012-11-09 03:01:31
字段 pxh name
1 小红
2 小红
3 大红
4 大红
5 美国
6 美国


要求查询 把name重复的去掉,并按pxh排序,不能用函数,存储过程,要一条语句写出来(查询结果只要name这个字段,不用显示pxh字段)
小红
大红
美国
...全文
237 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
坚_持 2012-11-10
  • 打赏
  • 举报
回复
ygnmn 2012-11-10
  • 打赏
  • 举报
回复
select distinct name from table order by pxh
xiaoqi7456 2012-11-10
  • 打赏
  • 举报
回复
select distinct name from table order by pxh
domorejojo 2012-11-10
  • 打赏
  • 举报
回复
推荐用distinct,
select distinct name from table order by pxh
不推荐用group by
select name from tb group by name order by min(pxh)
因为,你只是单纯的去重,用distinct就够了,用group by 会增加一遍表的循环。 小数据表,貌似他俩都可以了。但是如果数据有上千万,或者上千万的表去关联其他的表,这个时候就可以知道用distinct效率高的不止一个点了。
longai123 2012-11-10
  • 打赏
  • 举报
回复
select distinct name from table order by pxh;
Sylaro0 2012-11-09
  • 打赏
  • 举报
回复
create table #a1(pxh int,name nvarchar(10)) insert #a1 select 1,'小红' union all select 2,'小红'union all select 3,'大红'union all select 4,'大红'union all select 5,'美国'union all select 6,'美国' select name from #a1 group by name order by min(pxh)
PB菜鸟 2012-11-09
  • 打赏
  • 举报
回复
select distinct name from table order by pxh
發糞塗牆 2012-11-09
  • 打赏
  • 举报
回复
select name from tb group by name order by pxh
开启时代 2012-11-09
  • 打赏
  • 举报
回复
select distinct name from TB order by pxh
百年树人 2012-11-09
  • 打赏
  • 举报
回复
select name from tb group by name order by min(pxh)

34,571

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧