select * from articles where (title LIKE '%keywords%') or (content LIKE '%helloworld%') order by ((CASE WHEN title LIKE '%keywords%' THEN 2 ELSE 0 END) + (CASE WHEN content LIKE '%helloworld%' THEN 1 ELSE 0 END)) ASC, dateline DESC

解决方案 »

  1.   

    select *from tablename where a like 'xx*' 
    union all
    select *from tablename where b = 'xx' 
    union all
    select *from tablename where c = 'xx'
      

  2.   

    select * from test where a like 'xx%' or b = 'xx' or c = 'xx' order by 
    if(a like 'xx%', 3, if(b='xx',2,1)) desc 
      

  3.   


    select * ,CASE WHEN LENGTH(a,'xx') = 'xx' THEN 1
                              WHEN b = 'xx' THEN 2
                             WHEN c = 'xx' THEN 3
                             ELSE  4 END AS col
     from tablename where a like 'xx*' or b = 'xx' or c = 'xx'
    ORDER BY col
      

  4.   

    select *from tablename where a like 'xx*' or b = 'xx' or c = 'xx'
    order by a like 'xx*' desc,b = 'xx' desc, c = 'xx' desc