当前位置:网站首页>求MySQL先按大于等于当前时间升序排序,再按小于当前时间降序排序
求MySQL先按大于等于当前时间升序排序,再按小于当前时间降序排序
2022-06-11 02:18:00 【勤学如春起之苗】
现在有一个新闻表,表里面有一个时间字段。
我现在想要一条select查出来的数据,在排序上是先按大于等于当前时间升序排序,再按小于当前时间降序排序。
举个例子就是,比如今天是4月7号。我们数据库里有4月5号,4月6号,4月7号以及4月8号的新闻
那么我查出来的排序就是 -->4月7号,4月8号,4月6号,4月5号。
问题基本跟这个一样:http://bbs.csdn.net/topics/380215463
不过这个帖子说的是SQL Server,看了一下语句不能在MySQL里用。
用union all的话应该可以完成,但是如果要分页,需要limit的话,union all就不能满足需求了吧。
想请教一下有没有用一条语句,而且还可以保证分页可用的情况下解决这个问题的方法呢,求各位大神指点。
完美解决分页问题:
select * from yj_user order by cre_time<now(),if(cre_time<now(),0,cre_time),cre_time desc limit 0,10
bulongwind
关注
5
3
5
————————————————
版权声明:本文为CSDN博主「bulongwind」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/bulongwind/article/details/70156493
边栏推荐
- 基于互联网架构演进, 构建秒杀系统
- AOSP ~ modify default volume
- Uni app - one click access to user information
- Learning Tai Chi Maker - esp8226 (II)
- Unity3d model skin changing technology
- 6 best WordPress Image optimizer plug-ins to improve WordPress website performance
- helm 部署traefik ingress
- ADVANCE.AI首席执行官寿栋将在2022新兴市场品牌出海线上峰会分享跨境电商运用AI技术合规
- Unity determines whether the object is in the camera field of view
- AOSP ~ 修改默认音量
猜你喜欢

完成千万元A轮融资,小象生活能否成为折扣界的“永辉”?

重磅直播!ORB-SLAM3系列之特征匹配(MLPnP、词袋模型等)。

How to guarantee the data quality of data warehouse?

Modify release opening animation

【新晋开源项目】动态配置化任务编排框架 Gobrs-Async 加入Dromara开源社区

Jetpack compose scaffold and bottomappbar (bottom navigation)

mysql重装时写my.ini配置文件出错

你的公司会选择开发数据中台吗?

【189. 轮转数组】

Multilevel mesoporous organometallic framework material zif-8 loaded with lactic acid oxidase (LOD) / ferric oxide (Fe304) / doxorubicin / insulin /cas9 protein / metronidazole / emodin methyl ether
随机推荐
AOSP ~ 修改默认音量
PHP starts OpenSSL and reports OpenSSL support=> disabled (install ext/openssl)
CPT 102_LEC 18
【189. 轮转数组】
P4338 [ZJOI2018]历史(树剖)(暴力)
APP测试_测试点总结
net core天马行空系列-可用于依赖注入的,数据库表和c#实体类互相转换的接口实现
Sword finger offer II 079 All subsets
[Fibonacci series]
SQL | calculate sum
378. the k-th smallest element in an ordered matrix
P4338 [zjoi2018] history (tree section) (violence)
Google Gmail mailbox marks all unread messages as read at once
The Google search console webmaster tool cannot read the sitemap?
MySQL备份与恢复
扁平数据转tree与tree数据扁平化
[189. rotation array]
[AI weekly] AI and freeze electron microscopy reveal the structure of "atomic level" NPC; Tsinghua and Shangtang proposed the "SIM" method, which takes into account semantic alignment and spatial reso
Byte beating | the first batch of written examination for game R & D post (question solution)
Whether the software test needs to master the programming ability