当前位置:Gxlcms > PHP教程 > 数据库-php先按year倒序查询再按term为2的先查询为1的后查询

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

时间:2021-07-01 10:21:17 帮助过:2人阅读

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

)

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

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

)

回复内容:

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

)

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

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

)

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

ORDER BY `year` DESC, `term` DESC

人气教程排行