ZhuDongming
2019-06-12 0b646569a295da41eed5cbbcc80309a7472a47a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.moral.mapper.DemoMapper">
    <select id="getDatas" resultType="map">
        SELECT *
        FROM hangzhou_aqi
        <where>
            <if test="timeList != null and timeList.size &gt; 0">
                time IN
                <foreach collection="timeList" open="(" separator="," close=")"
                    item="listItem">
                    #{listItem}
                </foreach>
            </if>
        </where>
        ORDER BY time
        <if test="size != null">
            DESC 
            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>