标签:ble blank sts password var tor size div ==
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
`id` varchar(20) NOT NULL,
`name` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
insert into t_user values(1,‘汪峰‘,‘888888‘);
insert into t_user values(2,‘王汪峰‘,‘888888‘);
insert into t_user values(3,‘汪峰峰‘,‘888888‘);
insert into t_user values(4,‘欧阳汪峰‘,‘888888‘);
insert into t_user values(5,‘王汪峰峰‘,‘888888‘);
select * from t_user where name like ‘%汪峰%‘;
结果为:
可以发现,“汪峰峰”并没有排列在“王汪峰”前面
select * from t_user f where f.name like ‘%汪峰%‘ order by
(case
when f.name = ‘汪峰‘ then 1
when f.name like ‘汪峰%‘ then 2
when f.name like ‘%汪峰‘ then 3
when f.name like ‘%汪峰%‘ then 4
else 0
end ) limit 0,50;
查询结果为:
等于说额外添加了一个虚拟列,来辅助进行排序;
首先匹配完全==的,然后再按照规则匹配下一条数据,就能得到我们想要的结果了。
标签:ble blank sts password var tor size div ==
原文地址:https://www.cnblogs.com/scode2/p/9065946.html