mysql 查詢根據兩個或兩個以上欄位排序
阿新 • • 發佈:2019-02-14
以jibingName=腹痛 欄位為例 我們需要按照 jibingName 和 fenxing_id兩個欄位來進行排序
--------------------------------------------------------------------------------------------修改前----------------------------------------------------------------------------------------------------
順序按照分型表的id ,fenxing_id 和jibingName 欄位比較亂
sql
select t1.*,t2.name as jibingName
from
dt_bzzz_fenxing as t1
LEFT JOIN
dt_bzzz_jibing
AS t2
ON t1.class_id=t2.class_id AND t1.type=t2.type
ORDER BY t1.id
jibingName 打亂了 截圖第一張截圖第二張
--------------------------------------------------------------------------修改後-----------------------------------------------------------------------
sql語句
select t1.*,t2.name as jibingName
from
dt_bzzz_fenxing as t1
LEFT JOIN
dt_bzzz_jibing
AS t2
ON t1.class_id=t2.class_id AND t1.type=t2.type
ORDER BY t2.`name`,t1.fenxing_id
截圖第一張