- ON DUPLICATE KEY UPDATE为Mysql特有语法,当insert已经存在的记录时,执行Update
<insert id="mergeInto" parameterType="list" keyProperty="permissionId" useGeneratedKeys="true">
insert into sys_permission (permission_id,tag,summary,path,method)
values
<foreach collection="list" item="item" separator=",">
(
(select * from (select IFNULL(max(permission_id),#{item.permissionId}) from sys_permission where path=#{item.path}) as a),
#{item.tag},#{item.summary},#{item.path},#{item.method})
</foreach>
ON DUPLICATE KEY UPDATE
tag= VALUES(tag),
summary= VALUES(summary),
path= VALUES(path),
method= VALUES(method)
</insert>
- 构造DECODE函数的功能
# 构造DECODE函数的功能
# FIELD(str,str1,str2,str3,...)
# 返回值为str1, str2, str3匹配的下标,str表示计算的结果,在找不到str的情况下,返回值为 0
# ELT(N,str1,str2,str3,...)
# 若N = 1,则返回值为 str1 ,若N = 2,则返回值为 str2,以此类推。若N 小于1或大于参数的数目,则返回值为 NULL
# IFNULL(expr1,expr2)
# 假如expr1 不为 NULL,则 IFNULL() 的返回值为 expr1; 否则其返回值为 expr2
Select IFNULL(
ELT(
FIELD(1, 1, 2, 15, 16, 17, 18, 19)
,'Thirteen','Fourteen','Fifteen','Sixteen','Seventeen','Eighteen','Nineteen'
)
,'Adult') str;
- 日期/时间转换为字符串 函数:date_format(date,format)
select date_format('2008-08-08 22:23:01', '%Y%m%d%H%i%s');
- 字符串转换为日期)函数:str_to_date(str, format)
select str_to_date('08.09.2008 08:09:30', '%m.%d.%Y %h:%i:%s'); -- 2008-08-09 08:09:30
- 两个日期相减 date1 - date2,返回天数 函数:datediff(date1,date2)
select datediff('2008-08-08', '2008-08-01'); -- 7
- 两个日期相减 time1 - time2,返回 time 差值 函数:timediff(time1,time2)
两个日期相减 time1 - time2,返回 time 差值 函数:timediff(time1,time2)
- 时间差函数:TIMESTAMPDIFF
TIMESTAMPDIFF函数,有参数设置,可以精确到月(MONTH)天(DAY)、小时(HOUR),分钟(MINUTE)和秒(SECOND),使用起来比datediff函数更加灵活。对于比较的两个时间,时间小的放在前面,时间大的放在后面
--相差1天
select TIMESTAMPDIFF(DAY, '2018-03-20 23:59:00', '2015-03-22 00:00:00');
--相差49小时
select TIMESTAMPDIFF(HOUR, '2018-03-20 09:00:00', '2018-03-22 10:00:00');
--相差2940分钟
select TIMESTAMPDIFF(MINUTE, '2018-03-20 09:00:00', '2018-03-22 10:00:00');
- timediff输出转换为日,小时,分钟,秒格式 结果:4天20小时12分钟
SELECT CONCAT(
FLOOR(HOUR(TIMEDIFF('2010-01-06 08:46', '2010-01-01 12:30')) / 24), '天',
MOD(HOUR(TIMEDIFF('2010-01-06 08:46', '2010-01-01 12:30')), 24), '小时',
MINUTE(TIMEDIFF('2010-01-06 08:46', '2010-01-01 12:30')), '分钟')
- 查询字段(strlist)中包含(str)的结果,未查到结果返回0,反之返回查到的位置 函数:FIND_IN_SET(str,strlist)
SELECT FIND_IN_SET('c', 'a,b,c,d')
-
相关推荐
MySQL相关JAR包-
数据库相关的一些基础的文档,里面是一些面试的基础知识
2、通过datax同步mysql相关-mysql同步到mysql、mysql和hdfs相互同步 网址:https://blog.csdn.net/chenwewi520feng/article/details/130509875 介绍mysql的相关同步,mysql同步到mysql、mysql和hdfs相互同步
Lucene+mysql相关jar包。导入相关jar包用Lucene对数据库信息进行分词索引。
1.6 顺应2000年 1.7 SQL一般信息和教程 1.8 有用的MySQL相关链接 2 MySQL 邮件列表及如何提问或报告错误 2.1 MySQL邮件列表 2.2 提问或报告错误 2.3 怎样报告错误或问题 2.4 在...
mysql相关资料L. mysql相关资料L. mysql相关资料L.
mysql相关学习视频
Apache+php+mysql相关优化
搭建mysql相关文档
内含MySQL5.0和MySQL5.5两个版本的安装包及安装教程文档,以及数据库管理工具SQLyog。
1.6 顺应2000年 1.7 SQL一般信息和教程 1.8 有用的MySQL相关链接 2 MySQL 邮件列表及如何提问或报告错误 2.1 MySQL邮件列表 2.2 提问或报告错误 2.3 怎样报告错误或问题 ...
MySql相关学习
MySQL 相关学习
MySQL.rar MySQL.rar MySQL.rar
MySQL相关介绍 及优化
MySql相关面试题举例
mysql相关配置文件
mysql相关学习视频 1.2
适合linux无网环境下安装MySQL8.0版本