2014-04-08 37 views
0

我有一個查詢在那裏我得到的數據是這樣的:MySQL的:爲了通過查詢用戶定義的方式

fld_id | fld_type_id | fld_product 
----------------------------------- 
    81 | 1   | 25 
    82 | 2   | 25 
    83 | 3   | 25 
    84 | 4   | 25 

fld_type_id的順序是1,2,3,4,但我要的是安排這訂單在3,4,2,1我試圖做到這一點:

Select * from tbl 
where fld_product = 25 
Order by Case fld_type_id 
when 3 then 1 
when 4 then 2 
when 2 then 3 
else 4 

但它沒有幫助我......我該怎麼做?

回答

1

嘗試

Select *, 
Case fld_type_id when 3 then 1 
when 4 then 2 
when 2 then 3 
else 4 END as sOrder 
from tbl where fld_product = 25 Order by sOrder