mysql每日一题0809--每行包含某个特定数据或者字符 like regex like length
测试数据
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