ORDER BY在MySQL中无法正常工作

时间:2015-03-21 05:06:38

标签: mysql

以下是我想要SELECT ORDER BY的{​​{1}}查询,其中transType ='I',然后以变速顺序转换。通过该查询,我可以正确地获得transType ='I'记录,但之后它不会以正确的顺序显示。

  SELECT tranjectionId,date_format(transDate,'%d-%m-%Y') AS transDate,motiAmount,
                             transType,tranjection.partyId,item.itemName,gwt,loss,netwet,
                              party.partyName,melting,westage,finewet,rhodium,amount,bhav 
                         FROM  tranjection,party,item
                       WHERE party.partyId =  tranjection.partyId
                       AND item.itemId =  tranjection.itemId
                         AND tranjection.partyId = ".$partyId."
                        ORDER BY  (transType = 'R') DESC,
                                   transDate

1 个答案:

答案 0 :(得分:0)

在执行订单时,您可以执行

order by 
case 
  when transtype = 'I' then 0 else 1 
end,
transdate;