按月、按日进行数据统计的Mysql语句

<select id="getCustomerTJByUser" parameterType="map" resultType="map">
select u.username,
<if test="dateType==&quot;d&quot;">DATE_FORMAT(c.create_date,'%Y-%m-%d') createDate,</if>
<if test="dateType==&quot;m&quot;">DATE_FORMAT(c.create_date,'%Y-%m') createDate,</if>
COUNT(*) summer
from nb_custom c ,nb_user u
where 1=1
<if test="startDate!=null&amp;&amp;startDate!=&quot;&quot;"> and c.create_date &gt;= #{startDate}</if>
<if test="endDate!=null&amp;&amp;endDate!=&quot;&quot;"> and c.create_date &lt;= #{endDate}</if>
<if test="usernameTJ!=null&amp;&amp;usernameTJ!=&quot;&quot;"> and u.username=#{usernameTJ}</if>
<if test="createId!=null"> and u.create_id=#{createId}</if>
and u.state=1
and c.nu_id_oper=u.nu_id
GROUP BY createDate,u.username
</select>
posted @ 2016-11-08 11:56  小妮儿玩博客  阅读(364)  评论(0编辑  收藏  举报