postgresql 查询字符串中是否包含某字符的几种写法

原文链接:https://blog.csdn.net/cainiaobulan/article/details/88830929

先看表结构和数据:

 

需求:查询出manager_id中包含某些字符的数据,此处查询manager_id包含6651545956882725395,5722501350582149881的数据,SQL语句如下:

SELECT t.* from bas_cm_customer t where position('6651545956882725395' in t.manager_id) > 0 OR position ('5722501350582149881' in t.manager_id) > 0;

SELECT t.* from bas_cm_customer t where position('6651545956882725395' in t.manager_id) > 0 OR position('5722501350582149881' in t.manager_id) > 0 ;

SELECT t.* from bas_cm_customer t where strpos(t.manager_id,'6651545956882725395') > 0 or strpos(t.manager_id,'5722501350582149881') > 0;

SELECT t.* from bas_cm_customer t where '6651545956882725395' ~ t.manager_id or '5722501350582149881' ~ t.manager_id;

SELECT t.* FROM bas_cm_customer t WHERE (string_to_array('6651545956882725395,5722501350582149881', ',') && string_to_array(t.manager_id, ','))

 

posted @ 2020-05-11 16:53  紫晶城  阅读(9568)  评论(0编辑  收藏  举报