按mysql

时间:2018-05-20 07:14:48

标签: mysql

我有以下数据: enter image description here

我想要显示最近有'到期'地位第一。我该如何订购这些数据。

N.B:我正在使用Mysql数据库。

3 个答案:

答案 0 :(得分:3)

这应按顺序排列Due,Paid和其他人:

SELECT Date, Invoice, ProductName, Qty, Rate, TotalPrice, PaymentStatus, PaymentType
FROM xxxTable
ORDER BY CASE 
    WHEN PaymentStatus LIKE "%Due%" then 1 
    WHEN PaymentStatus LIKE "%Paid%"  then 2 
    ELSE 3 
END

答案 1 :(得分:0)

SELECT Date
     , Invoice
     , ProductName
     , Qty
     , Rate
     , TotalPrice
     , PaymentStatus
     , PaymentType
  FROM xxxTable
 ORDER
    BY PaymentStatus = 'Due' DESC 
     , date DESC

答案 2 :(得分:-1)

尝试:

   select   *
   from     yourtable
   order by
            `Payment Status`
            ,Date desc