通过case when提前查询部分统计信息
<resultMap type="com.entity.N25175Goods" id="gdCount">
<result column="date" property="date" />
<result column="inCount" property="inCount"/><!-- 总收入 -->
<result column="chargeCount" property="chargeCount"/><!-- 总取件费 -->
<result column="feeCount" property="feeCount" /><!-- 总派件费 -->
<result column="sanjianCount" property='sanjianCount'/><!-- 总散件运费 -->
<result column="zhengcheCount" property="zhengcheCount"/><!-- 总整车运费 -->
</resultMap>
<select id="selectRevenueStatistic" resultMap="gdCount">
select DATE_FORMAT(gd_ctime, '%Y-%m-%d') AS date,
SUM(gd_total) AS inCount, <!-- 总收入 -->
SUM(gd_charge) as chargeCount,<!-- 总取件费 -->
SUM(gd_fee) as feeCount, <!-- 总派件费 -->
SUM(CASE when gd_type=0 then gd_freight else 0 end) as sanjianCount,<!-- 散件运费 -->
SUM(CASE when gd_type=3 then gd_freight else 0 end) as zhengcheCount<!-- 整车运费 -->
from n25175_goods
<if test="dateStart!=null and dateEnd!=null">
where gd_ctime between #{dateStart} and #{dateEnd}
</if>
group by DATE_FORMAT(gd_ctime, '%Y-%m-%d')
</select>