我需要按兩列訂購一張桌子。
這是桌子

欄位 estado 只能具有三個不同的值:Pendiente、Gestionada 或 Archivada。
我需要首先顯示所有帶有 estado = "Pendiente" 訂單的 fecha 專案,然后顯示所有帶有 estado = "Archivado"" 的專案
這是我當前的查詢:
SELECT
alerta.id as id,
alerta.id_usuario as id_usuario,
alerta.id_tipo_alerta as id_tipo_alerta,
alerta.latitud as latitud,
alerta.longitud as longitud,
alerta.descripcion as descripcion,
alerta.estado as estado,
alerta.fecha as fecha,
alerta.leida as leida,
tip.tipo_alerta as tipo_alerta
FROM tb_alertas alerta
LEFT JOIN tb_tipos_alertas tip ON alerta.id_tipo_alerta = tip.id
WHERE alerta.estado = 'Gestionada' OR alerta.estado = 'Archivada'
ORDER by alerta.fecha, alerta.estado DESC
我需要在查詢中更改什么?
uj5u.com熱心網友回復:
使用該FIELD()函式指定estado列的順序。
ORDER BY FIELD(alerta.estado, 'Pendiente', 'Archivado', 'Gestionada'), alerta.fecha
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/418282.html
標籤:
上一篇:MySQL中創建函式陳述句的問題
下一篇:MySql存盤程序行問題
