稍微複雜點的 ,參數類型爲java
parameterType="java.util.HashMap"
返回類型爲resultMap sql
SELECT t.brand_id AS id, ifnull(SUM(t.day_wholesale),0) AS day_wholesale, ifnull(sum(t.day_retail),0) AS day_retail, ifnull(sum(t.month_w_task),0) AS w_task, ifnull(sum(t.w_total_task),0) AS w_total_task, ifnull(sum(t.month_r_task),0) AS r_task, ifnull(sum(t.r_total_task),0) AS r_total_task, ifnull(sum(t.society_inhouse_sum),0) AS society_inhouse_sum, ifnull(sum(t.society_in_transit),0) AS society_in_transit, ifnull(sum(t.society_no_send),0) AS society_no_send, ifnull(sum(t.day30_retail),0) AS day30_retail, ifnull( sum(t.society_inhouse_sum), 0 ) + ifnull(sum(t.society_no_send), 0) + ifnull( sum(t.society_in_transit), 0 ) AS stock_sum, ifnull(SUM(t.date1),0) AS date1, ifnull(SUM(t.date2),0) AS date2, ifnull(SUM(t.date3),0) AS date3, ifnull(SUM(t.date4),0) AS date4, ifnull(SUM(t.date5),0) AS date5 FROM ca_dealer_express t where t.date = #{date} and dealer_id = #{dealer_id} and t.c_type=0 <if test="brand_id!=null"> and t.brand_id =#{brand_id} group by brand_id </if>
其中sql查詢條件通常把能篩選出的東西少的條件放前面,通常是把整型放前面,而本例特殊,因此是把字符串放前面,一面產生是list時,也要放到後面,這樣會提速express