SQL分段排序数据库里有1,2,3,4,5 共5条记录,要用一条sql语句让其排序,使它排列成4,5,1,2,3,怎么写?
SQL分段排序 
CREATE TABLE #AAA (
SQL分段排序  
[id] [int] IDENTITY (11NOT NULL ,
SQL分段排序  
[GUID] [uniqueidentifier] NULL 
SQL分段排序 ) 
ON [PRIMARY]
SQL分段排序 
GO
SQL分段排序
SQL分段排序
SQL分段排序下面这句执行5次
SQL分段排序 
insert #AAA values (newid())
SQL分段排序
SQL分段排序查看执行结果
SQL分段排序 
select * from #AAA
SQL分段排序
SQL分段排序
1、 第一种
SQL分段排序 
select * from #AAA
SQL分段排序  
order by case id when 4 then 1
SQL分段排序                   
when 5 then 2
SQL分段排序                   
when 1 then 3
SQL分段排序                   
when 2 then 4
SQL分段排序                   
when 3 then 5 end
SQL分段排序
SQL分段排序
2、 第二种
SQL分段排序 
select * from #AAA order by (id+2)%6
SQL分段排序
SQL分段排序
3、 第三种
SQL分段排序 
select * from #AAA order by charindex(cast(id as varchar),'45123')
SQL分段排序
SQL分段排序
4、 第四种
SQL分段排序 
select * from #AAA
SQL分段排序 
WHERE id between 0 and 5
SQL分段排序 
order by charindex(cast(id as varchar),'45123')
SQL分段排序
SQL分段排序
5、 第五种
SQL分段排序 
select * from #AAA order by case when id >3 then id-5 else id end
SQL分段排序
SQL分段排序
6、 第六种
SQL分段排序 
select * from #AAA order by id / 4 desc,id asc
SQL分段排序

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-11-15
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案