SQL - retain ordering based on the query params

前端 未结 7 1928
借酒劲吻你
借酒劲吻你 2021-02-10 08:34

I\'m trying to perform a SELECT with an IN clause and I would like to be able to have the results returned in the same order as the elements in my list

7条回答
  •  北恋
    北恋 (楼主)
    2021-02-10 08:52

    you can try it will work fine. Check below sql:-

    SELECT * FROM orders WHERE order_no IN ('B123', 'B483', 'B100', 'B932') 
    ORDER BY DECODE(order_no,'B123','1','B483','2','B100','3','B932','4');
    

提交回复
热议问题