SqlServer 按指定顺序进行排序

sqlserver 专栏收录该内容
28 篇文章 0 订阅
SQLSERVER指定顺序排序代码为:
CHARINDEX(RTRIM(CAST(列名 as NCHAR)),您指定排序的类型或字符串)

如下:
select * from 表名 where 1=1  
order by CHARINDEX(RTRIM(CAST(列名 as NCHAR)),'2,3,1')  
结果是:2,3,1
select case when f.id=6 then 5 else f.id end as zb_tbdw,d.* from HrmSubCompany f left join 
(select a.zb_nf,a.zb_yf+1 yf ,a.zb_tbdw as zb_tbdw1 ,b.mx_rq 
,b.mx_jgzc,b.mx_zbld from dbo.formtable_main_66 a inner join 
dbo.formtable_main_66_dt1 b on a.id=b.mainid where a.zb_nf=${p1} 
and a.zb_yf=${p2}-1 and b.mx_rq=${p3} )
d on f.id=d.zb_tbdw1 where  f.id  in (6,55,56,78,57,58,59,71,72,70,79,60,61,76,66,67,68,75,69,62,65,63,64,73,74) 
order by CHARINDEX(RTRIM(CAST(id as NCHAR)),'6,55,56,78,57,58,59,71,72,70,79,60,61,76,66,67,68,75,69,62,65,63,64,73,74') 

注:https://www.jianshu.com/p/01a9eed5c31e

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值