<![CDATA[ ]]>表示不需要转义
时间格式转换:
<if test="date eq 'Day' ">
AND to_days(STR_TO_DATE(time,"%Y年%m月%d日 %H时%i分%s秒")) = to_days(now())
</if>
<if test="date eq 'Week' ">
AND YEARWEEK(STR_TO_DATE(time,"%Y年%m月%d日 %H时%i分%s秒")) = YEARWEEK(now())
</if>
<if test="date eq 'Mon' ">
AND DATE_FORMAT( STR_TO_DATE(time,"%Y年%m月%d日 %H时%i分%s秒"), '%Y%m' ) = DATE_FORMAT(CURDATE( ) , '%Y%m' )
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
<![CDATA[ AND date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') ]]>
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
<![CDATA[ AND date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') ]]>
</if>
<!--
<if test="minRequirementDate!=null and minRequirementDate!=''">
and <![CDATA[o.requirementDate >= STR_TO_DATE(#{minRequirementDate}, '%Y-%m-%d')]]>
</if>
-->
# YEAR(create_time)转为年
计算百分比:
select CompletedQuantity,ScrappedQuantity,
concat(cast((CompletedQuantity/(ScrappedQuantity+CompletedQuantity))*100 as decimal(4,2)),'%'),
concat(cast(100-((CompletedQuantity/(ScrappedQuantity+CompletedQuantity)))*100 as decimal),'%')
from operationtaskconfirm
# decimal(4,2)表示4位数字,两位小数
时间计算:
date(log_time) = date_sub(curdate(),interval 1 day);
括号中为当天时候的前一天,若是统计前几天就将括号中的’1’改成响应的天数。若是要算月或年,直接将day改为month或year即可
统计本周
请求: 统计从昨天开端统计前7天的日记包含昨天
date(log_time) >= date_sub(curdate(),interval 7 day)
and date(log_time) <= date_sub(curdate(),interval 1 day)
如果想要往后计算时间,要在数字前面加上负号
如:date(log_time) <= date_sub(curdate(),interval -1 day)
date_sub(""2012-05-25"",interval 1 day) 默示 2012-05-24
date_sub(""2012-05-25"",interval 0 day) 默示 2012-05-25
date_sub(""2012-05-25"",interval -1 day) 默示 2012-05-26