加上order by 字段1,字段2,字段3
{
      select * from   表名  order by 猪,狗,牛;
}应该就可以了

解决方案 »

  1.   

    猪,狗,牛是在同一字段中的,楼上的不行。可以这样写,例如字段名叫shengxiao$sqlstr = "select *,IF(shengxiao='猪啊',1, IF(shengxiao='狗啊',2,3)) as s from table order by s";
      

  2.   

    这样不行,猪,狗,牛不是字段,猪狗牛是数据
    查询是这样的
    $str="select id  from biaoqian  where (biaoti like '%猪%' or b.biaoti like '%狗%' or b.biaoti like '%牛%' or b.biaoti like '%猪狗牛%' )  order by  id desc limit 10";现在的搜索结果排序方式是按id的倒序排列,我想按照搜索结果包含的数据排列,
    包含 “猪狗牛”的排在第一,然后包含猪的排在第二,包含狗的排在第三,最后是包含牛的
      

  3.   

    create temporary table T
      select '猪啊' as f
      union select '牛啊'
      union select '狗啊';
    select *, if(locate('猪', f), '猪',if(locate('牛',f),'牛', if(locate('狗',f),'狗',''))) as x 
     from T order by find_in_set(x, '猪,狗,牛')f    x 
    猪啊 猪 
    狗啊 狗 
    牛啊 牛 
      

  4.   

    order by xx like '%猪%', xx   like '%狗%', xx like '%牛%' desc