mysql中對order by的函數substring_index() , find_in_set()使用


題目是這樣的:sql = "select  *  from table  where  id  in(3,1,2,5)";  怎樣使得查詢的結果按照 3 ,1 , 2, 5來排序;

答案:這兩個SQL函數在平時真心沒用使用到過啊   find_in_set()  和  substring_index()

    用法是這樣:

         select * from table   order by substring_index('3,1,2,5',id,1);

      select * from table  order by find_in_set(id,'3,1,5')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM