一个关于排序的问题?难

[复制链接]
查看11 | 回复4 | 2006-9-15 08:51:14 | 显示全部楼层 |阅读模式
a, b
1,1101,
1,2321,
1,3243,
2,3211,
2,2432,
2,3007,
2,4425,
2,3325,
3,2561,
3,6422,
3,2563,
现在有两列,a与b,我想将a列按照b列大小排序,如下面c列
a, b ,c
1,1101,1
1,2321,2
1,3243,3
2,2432,1
2,3007,2
2,3211,3
2,3325,4
2,4425,5
3,2561,1
3,2563,2
3,6422,3
回复

使用道具 举报

千问 | 2006-9-15 08:51:14 | 显示全部楼层
select a, b from Table group by a order by b
回复

使用道具 举报

千问 | 2006-9-15 08:51:14 | 显示全部楼层
我还要生成c列序号
回复

使用道具 举报

千问 | 2006-9-15 08:51:14 | 显示全部楼层
--生成测试数据
declare @t table(a int , b int)
insert into @t select 1,1101
union all select 1,2321
union all select 1,3243
union all select 2,3211
union all select 2,2432
union all select 2,3007
union all select 2,4425
union all select 2,3325
union all select 3,2561
union all select 3,6422
union all select 3,2563
--解决方法
select *,c=(select count(*) from @t b where a.a=b.a and a.b>=b.b) from @t a
order by 1,2
回复

使用道具 举报

千问 | 2006-9-15 08:51:14 | 显示全部楼层
好了,非常感谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行