此 myTable 显示 order by no asc
的所有行,
我的问题是,我想显示带有自定义 order by
的所有行,
部分第一行与当前日期具有相同的数据(使用 2015-09-18 作为当前日期),之后请根据最小的数字自定义行,因此之后的结果自定义 order by
将从 5,4,1,2,3 排序。
我如何用sql语句实现这一点?谢谢。
最佳答案
SELECT *
FROM table
ORDER BY
CASE
WHEN date(date) = curdate() THEN no * (-1) -- when date is current date, sort descending (ascending by negative ID, to reverse order)
ELSE no -- else keep default ascending sort order
END
关于mysql - Sql 语句 order by with 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32648172/