mysql -- 某年12个月的统计值
查阅了很多资料,以及试了很多次,才找到了正确方法:
mybatis(mysql 语法): resuletype 为 linkedHashMap 是为了返回时数据是按 1 ~ 12 月 的顺序返回的,并且返回结果为键值对。
<select id="statisticsNewOrderUser" resultType="java.util.LinkedHashMap">
SELECT
COUNT(CASE MONTH(mall_order.`add_time`) WHEN '1' THEN mall_order.`id` END ) AS '1' ,
COUNT(CASE MONTH(mall_order.`add_time`) WHEN '2' THEN mall_order.`id` END) AS '2' ,
COUNT(CASE MONTH(mall_order.`add_time`) WHEN '3' THEN mall_order.`id` END) AS '3',
COUNT(CASE MONTH(mall_order.`add_time`) WHEN '4' THEN mall_order.`id` END) AS '4',
COUNT(CASE MONTH(mall_order.`add_time`) WHEN '5' THEN mall_order.`id` END) AS '5',
COUNT(CASE MONTH(mall_order.`add_time