<select id="statOnlineAndNotlineNumber" resultType="java.util.Map" parameterType="java.lang.String" >
SELECT
online_state as state,
COUNT(online_state) as number
FROM
wl_rm_t_vehicle_state
<if test="operatorCode!=null and operatorCode!=''">
where operator_code LIKE CONCAT(#{operatorCode},'%')
</if>
GROUP BY
online_state
</select>
其中列名 state、number对应key ,查出来的值对应value
mapper接口定义
List<Map<String,String>> statOnlineAndNotlineNumber(@Param("operatorCode") String operatorCode);
map应该装在list集合中,不然列名对应对个值时会报TooManyResultsException:
查出的结果如下: [{number=11, state=1}, {number=6, state=2}]