达梦数据库中如何改写MySQL order by in() 语法

MySQL数据库中有一种特殊的语法,order by if() 和order by in(),可以在order by子句中加入过滤条件,将符合条件的数据放到结果集的最前面或者最后面,那么在达梦数据库中该如何做呢?

create table test_in(id int,type int);

insert into test_in values(1,1);
insert into test_in values(2,2);
insert into test_in values(3,2);
insert into test_in values(4,3);
insert into test_in values(5,4);
insert into test_in values(6,6);
insert into test_in values(7,5);
insert into test_in values(8,7);

--MySql语法把 type 为2和3的值放到结果集的最前面
select * from test_in order by type in(2,3);  


--达梦数据库改写方法,order by子句中加入case语句来做条件判断
select
        id,
        type
from
        test_in
order by
        case when type in(2, 3) then 0 else 1 end,
        type

更多资讯请上达梦技术社区了解: https://eco.dameng.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值