<?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.ningdatech.carapi.scheduler.mapper.VehicleStatusMapper">

    <select id="getVehicleStatusInGps" resultType="com.ningdatech.carapi.scheduler.model.dto.VehicleStatusDTO">
        select aa.car_plate,aa.status,aa.update_time
        from nd_data_access_gps_${date} as aa
                 right join (
            select car_plate, max(update_time) as max
            from nd_data_access_gps_${date}
            WHERE
                update_time BETWEEN DATE_SUB(now(), INTERVAL #{timeScope} minute) AND now()
              AND STATUS IS NOT NULL
            group by car_plate
        ) as bb
        on bb.max = aa.update_time and bb.car_plate = aa.car_plate
            and aa.update_time BETWEEN DATE_SUB(now(), INTERVAL #{timeScope} minute) AND now()
            AND aa.STATUS IS NOT NULL
            AND aa.update_time IS NOT NULL
    </select>
</mapper>
