<?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.xy.mapper.DeviceNetRecordMapper">

    <!-- 离线设备列表 -->
    <select id="offLineDevice" resultType="com.xy.dto.DeviceNetRecordDto$OffLineDeviceVo">
        SELECT nd.device_id deviceId, nd.create_time createTime, di.device_name deviceName, di.merc_id mercId, di.merc_name mercName FROM (
        SELECT a.device_id, a.create_time
        FROM (
                SELECT device_id, MAX(create_time) AS create_time
                FROM device_net_record
                WHERE net_status = 2 and create_time >= #{beginTime} and create_time &lt;= #{endTime}
                GROUP BY device_id
        ) a
        LEFT JOIN (
                SELECT device_id
                FROM device_net_record
                WHERE net_status = 1 and create_time >= #{beginTime} and create_time &lt;= #{endTime}
                GROUP BY device_id
        ) b ON a.device_id = b.device_id
        WHERE b.device_id IS NULL
        ORDER BY a.create_time DESC
    ) nd
    join device_info di on(nd.device_id = di.device_id)
    </select>

</mapper>
