当前位置:网站首页>MySQL is required to sort in ascending order greater than or equal to the current time, and then in descending order less than the current time

MySQL is required to sort in ascending order greater than or equal to the current time, and then in descending order less than the current time

2022-06-11 02:46:00 Diligent learning is like the seedling of spring

Now there is a news table , There is a time field in the table .


I want one now select The data we found out , In sorting, you first sort by ascending order greater than or equal to the current time , Then sort in descending order less than the current time .


For example , For example, today is 4 month 7 Number . We have... In our database 4 month 5 Number ,4 month 6 Number ,4 month 7 And 4 month 8 News on
So the order I found out is  -->4 month 7 Number ,4 month 8 Number ,4 month 6 Number ,4 month 5 Number .


The problem is basically the same :http://bbs.csdn.net/topics/380215463


But this post says SQL Server, After a look, the sentence can't be in MySQL In the use .
use union all Should be able to complete , But if you want to page , need limit Words ,union all Can't meet the demand .


I would like to ask if there is a sentence , And it can also be used to solve this problem when paging is available , I beg your guidance .


Perfect solution to paging problems :

select * from yj_user order by cre_time<now(),if(cre_time<now(),0,cre_time),cre_time desc limit 0,10

bulongwind
Focus on

5


3

5

————————————————
Copyright notice : This paper is about CSDN Blogger 「bulongwind」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/bulongwind/article/details/70156493

原网站

版权声明
本文为[Diligent learning is like the seedling of spring]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110218252969.html