postgres、mysql计算字段里出现某字符的次数
SELECT array_length(regexp_split_to_array(gs.gss,'ss'),1)-1 as num from table gs若有特殊字符,用\转译如下,查询 /* 和 */出现的次数不相等的记录:(*是特殊字符)SELECT * from (SELECT array_length(regexp_split_to_array(gs.gss,'/\*'),1)-1
·
postgres:
SELECT array_length(regexp_split_to_array(gs.gss,'ss'),1)-1 as num from table gs
若有特殊字符,用\转译
如下,查询 /* 和 */出现的次数不相等的记录:(*是特殊字符)
SELECT * from (
SELECT array_length(regexp_split_to_array(gs.gss,'/\*'),1)-1 as le, array_length(regexp_split_to_array(gs.gss,'\*/'),1)-1 as rrrr, gs.id from table gs
) a where a.le != a.rrrr
mysql:
SELECT array_length(regexp_split_to_array(gs.gs,'/\*'),1)-1 as le
SELECT * from (
SELECT LENGTH(gs.gs)-LENGTH(REPLACE(gs.gs,'/\*','')) as le ,LENGTH(gs.gs)-LENGTH(REPLACE(gs.gs,'\*/','')) as rrrr from t_jxsjgsb gs
) a where a.le != a.rrrr
更多推荐
已为社区贡献2条内容
所有评论(0)