1.按照特定字段;
2.在某一日期范围内;
3.按日、按月统计;
4.动态传入数据库表名称。
select <if test="dateType=="d"">DATE_FORMAT(tj.trans_date,'%Y-%m-%d') date1,</if>
<if test="dateType=="m"">DATE_FORMAT(tj.trans_date,'%Y-%m') date1,</if>
c1.customer_name customerName,p.product_name productName,tj.result result,count(0) tjl,his.run_state runState
from ${tableName} tj,tableName1 c1,tableName2 his,tableName3 p
where c1.customer_id=tj.customer_id and tj.trans_id=his.trans_id and tj.product_id=p.product_id
<if test="startDate!=null&&startDate!="""> and DATE_FORMAT(tj.trans_date,'%Y-%m-%d') >= #{startDate}</if>
<if test="endDate!=null&&endDate!="""> and DATE_FORMAT(tj.trans_date,'%Y-%m-%d') <= #{endDate}</if>
<include refid="WHERE_CONDITIONS"/>
GROUP BY date1,customerName,result,runState