请教一个SQL语句

吹雪风 2007-06-19 02:09:25
有表test如下:
a varchar(2),b int

数据为:
a b
------------
x0 1
x2 2
x1 3
x2 4
x1 5

希望得到结果为:
x0
x2
x1

即按b排序,且去除掉已取到的数据,请问可以用一个SQL语句实现吗?
...全文
149 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ojuju10 2007-06-19
  • 打赏
  • 举报
回复
select a from test a
where not exists(select 1 from test where a.a=a and a.id>id)
order by b
ojuju10 2007-06-19
  • 打赏
  • 举报
回复

select a from test a
where not exists(select 1 from test where a.a=a and a.id>id)
fwacky 2007-06-19
  • 打赏
  • 举报
回复
declare @table table(a varchar(2),b int)

insert into @table
select 'x0' , 1 union all select
'x2' , 2 union all select
'x1' , 3 union all select
'x2' , 4 union all select
'x9' , 4 union all select
'x1' , 5
select * from @table

select distinct max( a) from @table group by b

希望得到结果为:

x0
x1
x2
x9
vchao13 2007-06-19
  • 打赏
  • 举报
回复
没看明白
chuifengde 2007-06-19
  • 打赏
  • 举报
回复
select a from test a where not exists(select * from test where a=a.a and b<a.b)
foolman888 2007-06-19
  • 打赏
  • 举报
回复
SELECT a FROM test GROUP BY a ORDER BY b asc
paoluo 2007-06-19
  • 打赏
  • 举报
回复
?

Select a From test Group By a Order By Min(b)

34,593

社区成员

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

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