1. round(x,d)
把x保留d位小數(shù)
2. period_diff()
相隔月/年
description
period_diff(date_format(current_date,"%Y%m"),date_format("2016-7-6","%Y%m"))
note
不能是相隔的天數(shù),不然計算出來的數(shù)有問題
period_diff(date_format(current_date,"%Y%m%d"),date_format("2010-09-01 00:00:00","%Y%m%d"))
datediff()
計算兩個日期之間的天數(shù)
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