Home  >  Article  >  Backend Development  >  关于排序问题

关于排序问题

WBOY
WBOYOriginal
2016-06-23 13:56:28835browse

比方说有2个字段  1个是时间 1个是id
id  time




我想先order by id  

3 444
3 555

2   222
2  333

然后再order by time

变成
3 444
3 555

2   333
2  222

怎么写 注意   33  22 都分组来排序的


回复讨论(解决方案)

如果最后结果是这个,可以这样写 order by id desc,time desc
3 555
3 444
2 333
2 222

你的要求是否为:
奇数 id 的 time 升序
偶数 id 的 time 降序

如果是的话,则 order 子句为:
order by id desc, id%2

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