Home > Backend Development > PHP Tutorial > 数据库 - php先按year倒序查询 再按term为2的先查询 为1的后查询

数据库 - php先按year倒序查询 再按term为2的先查询 为1的后查询

WBOY
Release: 2016-06-06 20:40:24
Original
1091 people have browsed it

<code>Array
(
    [id] => 1
    [user_id] => 1
    [year] => 2013-2014
    [term] => 1

)
Array
(
    [id] => 2
    [user_id] => 1
    [year] => 2013-2014
    [term] => 2

)
Array
(
    [id] => 3
    [user_id] => 1
    [year] => 2012-2013
    [term] => 1

)
</code>
Copy after login
Copy after login

如上面 先在year倒序查询的情况下 再按term为2的先查询 为1的后查询 最好用thinkphp
应该查出来是这样的

<code>Array
(
    [id] => 2
    [user_id] => 1
    [year] => 2013-2014
    [term] => 2

)
Array
(
    [id] => 1
    [user_id] => 1
    [year] => 2013-2014
    [term] => 1

)
Array
(
    [id] => 3
    [user_id] => 1
    [year] => 2012-2013
    [term] => 1

)
</code>
Copy after login
Copy after login

回复内容:

<code>Array
(
    [id] => 1
    [user_id] => 1
    [year] => 2013-2014
    [term] => 1

)
Array
(
    [id] => 2
    [user_id] => 1
    [year] => 2013-2014
    [term] => 2

)
Array
(
    [id] => 3
    [user_id] => 1
    [year] => 2012-2013
    [term] => 1

)
</code>
Copy after login
Copy after login

如上面 先在year倒序查询的情况下 再按term为2的先查询 为1的后查询 最好用thinkphp
应该查出来是这样的

<code>Array
(
    [id] => 2
    [user_id] => 1
    [year] => 2013-2014
    [term] => 2

)
Array
(
    [id] => 1
    [user_id] => 1
    [year] => 2013-2014
    [term] => 1

)
Array
(
    [id] => 3
    [user_id] => 1
    [year] => 2012-2013
    [term] => 1

)
</code>
Copy after login
Copy after login

ORDER关键字是可以给多个字段的

<code>ORDER BY `year` DESC, `term` DESC
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template