簡體   English   中英

SQL語句按條件排序?

[英]Sql statement order by with condition?

這個myTable order by no asc顯示所有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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM