<select id="getSaleData" resultType="map">
SELECT
FORMAT((SUM(t.totalMoney)/10000), 2) AS totalMoney,
SUM(t.amount) AS totalAmount,
<if test="type != null and type != ‘‘ and type==‘year‘">
date_format(t.addTime,‘%Y‘) as riqi
</if>
<if test="type != null and type != ‘‘ and type==‘season‘">
QUARTER(t.addTime) as riqi
</if>
<if test="type != null and type != ‘‘ and type==‘month‘">
date_format(t.addTime,‘%Y-%m‘) as riqi
</if>
<if test="type != null and type != ‘‘ and type==‘week‘">
date_format(t.addTime, ‘%Y-%m-%d‘) as riqi
</if>
FROM
destoon_orderform t
WHERE
1 = 1
AND t.orderStatus != ‘90‘
<if test="type != null and type != ‘‘ and type==‘year‘">
GROUP BY date_format(t.addTime,‘%Y‘)
</if>
<if test="type != null and type != ‘‘ and type==‘season‘">
AND date_format(t.addTime,‘%Y‘)=date_format(now(),‘%Y‘)
GROUP BY QUARTER(t.addTime)
</if>
<if test="type != null and type != ‘‘ and type==‘month‘">
AND date_format(t.addTime,‘%Y‘)=date_format(now(),‘%Y‘)
GROUP BY date_format(t.addTime,‘%Y-%m‘)
</if>
<if test="type != null and type != ‘‘ and type==‘week‘">
AND YEARWEEK(date_format(t.addTime,‘%Y-%m-%d‘)) = YEARWEEK(now())
GROUP BY date_format(t.addTime, ‘%Y-%m-%d‘)
</if>
</select>
原文:https://blog.51cto.com/brightaries/2534784