Home >Backend Development >PHP Tutorial >mysql排序问题~

mysql排序问题~

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-20 12:31:261010browse

我现在有两个字段 addDay(添加时间)和status(状态)。
我想要实现以下排序方式:
1.按addDay降序排列,并且status升序排列且status2.把status>=6的放在规则1的后面,并且按addDay降序和status升序排列

addDay         status
2016-4-14    1
2016-4-14    2
2016-4-13    1
2016-4-13    2
2016-4-14    6
2016-4-13    6

请问各位大神,这样的排序,应该如何写sql语句?


回复讨论(解决方案)

select addDay,status from table where status < 6 order by addDay desc,status ascunion allselect addDay,status from table where status >= 6 order by addDay desc,status asc

order by case when status<6 then addDay else 1 end desc,status asc

order by case when status<6 then addDay else 1 end desc,addDaydesc,status asc

select * from table order by if(status

select * from tbl_name order by status>=6, addDay desc, status asc

谢谢各位了,问题已经解决了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn