1. round(x,d)
把x保留d位小数
2. period_diff()
相隔月/年
description
period_diff(date_format(current_date,"%Y%m"),date_format("2016-7-6","%Y%m"))
note
不能是相隔的天数,不然计算出来的数有问题
period_diff(date_format(current_date,"%Y%m%d"),date_format("2010-09-01 00:00:00","%Y%m%d"))
datediff()
计算两个日期之间的天数
datediff(startDate,endDate)
datediff(date_format(current_date,"%Y%m%d"),date_format("2010-09-01","%Y%m%d"))
3. 截取字段
从左开始截取字符串, left(str,length)
select left("abcdefg",3) //"abc"
从右开始截取字符串,right(str,length)
select right("abcdef",3);
截取字符串, substring(str,startPoint,length)
substring("abcdef",2,4) //bcde
4. date_sub()N天前
语法
date_sub(date,interval expr type)
示例
select date_sub(current_date,interval 180 day);
5. 最近6个月
select time between date_sub(current_date,interval 180 day) and current_date