21,890
社区成员
发帖
与我相关
我的任务
分享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
猪啊 猪
狗啊 狗
牛啊 牛
$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的倒序排列,我想按照搜索结果包含的数据排列,
包含 “猪狗牛”的排在第一,然后包含猪的排在第二,包含狗的排在第三,最后是包含牛的
$sqlstr = "select *,IF(shengxiao='猪啊',1, IF(shengxiao='狗啊',2,3)) as s from table order by s";