请问如何实现该效果,谢谢!

alextoby 2006-07-05 05:11:07
数据表:
Id Type
1 A
2 B
3 C
4 A
5 B
6 C
7 A
8 B
9 C

如果得到以下结果
7 A
8 B
9 C
4 A
5 B
6 C
1 A
2 B
3 C

谢谢!
...全文
103 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
alextoby 2006-07-05
  • 打赏
  • 举报
回复
谢谢谢谢!俺要继续努力啊!!~~~~~>_<~~~~~
LouisXIV 2006-07-05
  • 打赏
  • 举报
回复
玩了会儿Google Earth,被挤到那么后面去了^^;
LouisXIV 2006-07-05
  • 打赏
  • 举报
回复
declare @a table
(
id int,
type char(1)
)
insert into @a
select 1,'A' union all
select 2,'B' union all
select 3,'C' union all
select 4,'A' union all
select 5,'B' union all
select 6,'C' union all
select 7,'A' union all
select 8,'B' union all
select 9,'C'

select *
from @a a
order by (select count(1) from @a where id<a.id and type=a.type)desc,id
paoluo 2006-07-05
  • 打赏
  • 举报
回复

select
a.*
from
tname a
order by
(select count(*) from tname where Type=a.Type and Id>=a.Id) ,Id


可以不用倒序的,查找大於等於的即可。
xyxfly 2006-07-05
  • 打赏
  • 举报
回复
路过,学习:)
fcuandy 2006-07-05
  • 打赏
  • 举报
回复
子陌老大正解
子陌红尘 2006-07-05
  • 打赏
  • 举报
回复
select
a.*
from
tname a
order by
(select count(*) from tname where Type=a.Type and Id<=a.Id) desc,Id

34,593

社区成员

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

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