MySQL 常用函数

1 字符串

1.1 替换字符串 REPLACE

update 表名 set 字段名=REPLACE (字段名,'原来的值','要修改的值')
update aaa set ac_name = REPLACE(ac_name,'积分星球','积分中心')  where ac_name like '%积分星球%';

1.2 字符串交集

求两个字符串是否有交集,比如表中数据是 1,2,3 ,搜索条件是 2,3,4,需要查询到交集数据。

select * from user where concat(column1, ',') regexp concat(replace(#{request.str2},',',',|'),',')
//str1 为字段名 ; 

1.3 时间段交集

查询两个时间段的交集
数据库的字段 start_time, end_time,输入的字段 startTime, endTime

方法一:

 select * from xxxx where 
(start_time <= startTime and end_time >= startTime)
or
(start_time <= endTime and end_time >= endTime)
or
(start_time >= startTime and end_time <= endTime)
or
(start_time s= startTime and end_time >= endTime);

方法二:通过取反获取交集

select * from xxxx where
!(start_time > endTime or end_time <= startTime);

方案三:重叠函数

select * from xxxx where
INTERVAL(start_time, end_time) INTERSECT INTERVAL (startTime, endTime)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容