mysql每日一题0809--每行包含某个特定数据或者字符 like regex like length

image

测试数据

CREATE TABLE T0809
(
ID INT,
DATA VARCHAR(10)
);

INSERT INTO T0809 VALUES(1,'8'),
(2,'88'),
(3,'7,8'),
(4,'6,7,8'),
(5,'8,9'),
(6,'7,88')

solution

select *   from T0809 where 
LENGTH(data)-LENGTH(replace(data,'8','')) <2 
and LENGTH(data)-LENGTH(replace(data,'8',''))>0




SELECT t.*FROM t0809 tWHERE REGEXP_Count(t.data,8,1)=1


posted on 2021-08-10 18:35  多一点  阅读(57)  评论(0编辑  收藏  举报

导航