分享一个不错的mysql语句

SELECT id, city_id, title, introduce, tags, avg_price, promotion, meeting_info, start_time, end_time, memo, registor_num,if(unix_timestamp() < start_time, 2, if(start_time < unix_timestamp() <= end_time, 3, 1)) as orderBy FROM `group_visit_house` `t` WHERE del_flag = 0 and is_show = 1 and city_id = 3 and start_time < unix_timestamp() and end_time > unix_timestamp() ORDER BY orderBy DESC, if(orderBy=3,"start_time DESC",if(orderBy=2, "start_time ASC", "end_time DESC"))

orderBy别名,当数据库时间小于start_time时候orderBy为1,在start_time和end_time之间时候为3,其余情况为1,然后根据orderBy排序,排序后再分别根据orderBy分别排序

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值