mysql 与 mybatis 错误记录
DATE_FORMAT(FROM_UNIXTIME(start_time / 1000)只能传秒级时间戳,毫秒级时间戳group后不能select;
tinyint(1)会被mybatis自动翻译为Boolean值,可以使用resultMap重新映射一下来解决,select使用了别名,在resultMap中映射column也必须别名。
<resultMap id="statisticsListItem" type="java.util.HashMap">
<result property="distanceType" column="distance_type" javaType="java.lang.Integer"/>
<result property="dateStr" column="dateStr" javaType="java.lang.String"/>
<result property="total" column="total" javaType="java.lang.Long"/>
<result property="correct" column="correct" javaType="java.lang.Long"/>
</resultMap>
<select id="statisticsList" resultMap="statisticsListItem" >
SELECT distance_type,DATE_FORMAT(FROM_UNIXTIME(start_time / 1000), '%Y-%m-%d') as dateStr,count(1) as total,sum(if(is_correct=0,1,0)) as correct
FROM `collision_situation` WHERE start_time>#{startDate} AND #{endDate}>start_time and NOT ISNULL(end_time)
GROUP BY concat(DATE_FORMAT(FROM_UNIXTIME(start_time), '%Y-%m-%d'),distance_type)
GROUP BY concat(DATE_FORMAT(FROM_UNIXTIME(start_time / 1000), '%Y-%m-%d'),distance_type)
</select>