我試圖讓一個ORDER BY野外作業使用通配符,並已成功:MySQL的ORDER BY字段%
SELECT positions.*,
departments.dept_name,
departments.dept_url,
divisions.dept_name AS div_name
FROM positions LEFT JOIN departments
ON positions.colleague_dept_code = departments.colleague_code
LEFT JOIN departments AS divisions
ON positions.colleague_div_code = divisions.colleague_code
WHERE colleague_id = '$colleague_id'
ORDER BY FIELD(positions.colleague_position_id, 'A%', 'F%', 'T%', 'S%', 'C%')
的colleague_position_id
領域有我們的MIS系統生成的文字標識,和我'd喜歡以A開頭的職位首先展示,F展示第二個等,等等。
任何幫助你可以提供將不勝感激。
謝謝!
你可以爲你的職位創建一個單獨的表,並有一個'等級'列嗎?然後,您可以加入您現有的查詢並通過positrion.rank進行訂購。 – 2012-03-29 01:12:11
不可以,因爲不幸的是,每個職位ID是不同的,我們確定職位的唯一方法是基於這封信。沒有任何數字將它們綁在一起 – Pete 2012-03-29 01:20:35