我有一张 table

id  name   status
---------------------
1   John   Approved
2   Kelly  Pending
3   Iva    Pending
5   Denis  Rejected
6   Michael Approved

我想以这样的方式分组和排序,它首先显示待处理的记录,第二个批准并最后拒绝

最佳答案

SELECT *
FROM tableName
ORDER BY FIELD(`status`, 'Pending','Approved','Rejected')
  • SQLFiddle Demo
  • SQLFiddle Demo (added another case)

  • 来源
  • FIELD
  • 关于mysql - sql中的排序词,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13567243/

    10-16 23:07