猪,狗,牛是在同一字段中的,楼上的不行。可以这样写,例如字段名叫shengxiao$sqlstr = "select *,IF(shengxiao='猪啊',1, IF(shengxiao='狗啊',2,3)) as s from table order by s";
这样不行,猪,狗,牛不是字段,猪狗牛是数据 查询是这样的 $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的倒序排列,我想按照搜索结果包含的数据排列, 包含 “猪狗牛”的排在第一,然后包含猪的排在第二,包含狗的排在第三,最后是包含牛的
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 猪啊 猪 狗啊 狗 牛啊 牛
order by xx like '%猪%', xx like '%狗%', xx like '%牛%' desc
查询是这样的
$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的倒序排列,我想按照搜索结果包含的数据排列,
包含 “猪狗牛”的排在第一,然后包含猪的排在第二,包含狗的排在第三,最后是包含牛的
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
猪啊 猪
狗啊 狗
牛啊 牛