-- mysql 获取当前时间大于前一天
SELECT * FROM t_log t where t.CREATE_TIME > date_sub(curdate(),interval 1 DAY);
-- db2
select * from t_log where CREATE_TIME > CURRENT DATE-1 DAY;
-- mysql 获取时间加上一天(正号代表 向前推时间 正数代表往后减时间) INTERVAL 间隙
SELECT (date_sub( t.CREATE_TIME, INTERVAL -1 DAY )) FROM t_log t ;
-- db2 获取时间加上一天
select ( VALUES TIMESTAMP(to_char( CREATE_TIME,'yyyy-mm-dd')) + 1 DAY ) FROM t_log;
-- mysql 减去时间
SELECT YEAR(CURRENT_DATE()-YEAR("2017-12-21"))>6
-- db2 db2 current date 减去一天 减去 一年 -12 MONTH
SELECT * FROM dept t where t.rksj > (current date-1 days)
https://www.cnblogs.com/rainbow-sea/p/14141547.html
-- DB2 COALESCE 第一个不存在 第二个 to_char时间转换
COALESCE(to_char(CREATE_TIME, 'yyyy-mm-dd hh24:mi:ss'),to_char(QUERY_TIME, 'yyyy-mm-dd hh24:mi:ss')) AS TIME
-- MYSQL
将日期时间2016-05-13 16:07:50转化为字符串20160513
select phone, date_format(time, '%Y-%m-%d %H:%i:%s') from user where phone='xxxxxxxx' #20160513160750
select phone, date_format(time, '%Y%m%d') from user where phone='xxxxxxxx' #20160513
SELECT
phone,
date_format( time, '%Y-%m-%d %H:%i:%s' )
FROM
USER
WHERE
phone = 'xxxxxxxx' #2021-01-01 08:18:39
SELECT
phone,
date_format( time, '%Y%m%d' )
FROM
USER
WHERE
phone = 'xxxxxxxx' #20210101
拼接字段 concat
- 例如:查询时要在一个字段中 stu_id、stu_name,中间用 '# ' 连接,mysql 语句:
- SELECT CONCAT(stu_id, '# ', stu_name) FROM student;
链接中间用":"
<select id="getSkuSaleAttrValuesAsStringList" resultType="java.lang.String">
SELECT CONCAT(attr_name,":",attr_value) //链接中间用":"
FROM `pms_sku_sale_attr_value`
WHERE sku_id=#{skuId}
</select>