mysql 正序_请问mysql 中 怎么实现这种排序,按照状态排序正序,再按照开始时间排序正序,...

展开全部

有两个思路

1、按照各自的活动状态先排序,插入到临时表,最后再union all所有结32313133353236313431303231363533e58685e5aeb931333363353862果集create temporary table tmp1

select * from tb where 活动状态='筹备中' order by 开始时间;

create temporary table tmp2

select * from tb where 活动状态='进行中' and 开始时间 is not null order by 开始时间;

create temporary table tmp3

select * from tb where 活动状态='进行中' and 开始时间 is null;

create temporary table tmp4

select * from tb where 活动状态='已结束' order by 开始时间 desc;

(select * from tmp1)

union all

(select * from tmp2)

union all

(select * from tmp3)

union all

(select * from tmp4)

2、通过field函数自定义排序

select * from tb order by field(活动状态,'筹备中','进行中','已结束') asc,开始时间 asc;

但这种只能按指定排序,你这种多种排序,有困难。

可以看看上面两种方法结合或许有更好的方法。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值