fengxiang
2018-07-30 04167f529701b8a88ef52ba7ae854f444347f72c
src/main/resources/mapper/DemoMapper.xml
@@ -19,4 +19,18 @@
         LIMIT #{size}
      </if>
   </select>
   <select id="selectByTimeZones" resultType="map">
      select * from hangzhou_aqi where time in (
         SELECT max(time) from (
          select time,cast(aqi_json->"$.AQI" as SIGNED INTEGER) as aqi from hangzhou_aqi
         ) hz where EXISTS ( select *  from (
                  select max(cast(aqi_json->"$.AQI" as SIGNED INTEGER)) as max_aqi,
                  DATE_FORMAT(time,'%Y-%m-%d') as day_time
                  from hangzhou_aqi
                  where time >= #{startTime} and time <![CDATA[<=]]> #{endTime}
                  GROUP BY day_time
               ) as max_result where day_time = DATE_FORMAT(hz.time,'%Y-%m-%d') and  max_aqi = hz.aqi
         ) GROUP BY DATE_FORMAT(time,'%Y-%m-%d') ORDER BY time ASC
      )
   </select>
</mapper>