<?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.car.rpt.mapper.RptDailySpecialVehiclesOverspeedMapper">
    <select id="report" resultType="com.ningdatech.carapi.car.rpt.model.po.RptDailySpecialVehiclesOverspeedPO">
        SELECT
        (case when r.level = 3 then r2.name else r.name end) name,
        count(case when ((o.max_speed - o.limit_speed)/o.limit_speed) &gt;= 0.2 and (o.max_speed - o.limit_speed)/o.limit_speed &lt;= 0.5 then 1 end) overspeed2050VehicleNums,
        count(case when (o.max_speed - o.limit_speed)/o.limit_speed &gt; 0.5 then 1 end) overspeed50VehicleNums
        FROM
        `nd_vehicle_overspeed_info` o
        left join nd_vehicle_base_info b on o.car_plate = b.car_plate
        left join nd_region r on o.region_id = r.id
        left join nd_region r2 on r.parent_id = r2.id
        left join nd_company_info c on o.company_id = c.id
        where o.deleted = 0 and o.max_speed is not null and o.limit_speed is not null
        and b.deleted = 0 and b.audit_state = 2 and b.vehicle_type in (1,2,3,4)
        <if test="param.date != null and param.date != ''">
            and o.overspeed_date between concat(#{param.date},' 00:00:00') and concat(#{param.date},' 23:59:59')
        </if>
        ${param.dataScopeSql}
        group by (case when r.level = 3 then r2.name else r.name end)
    </select>
</mapper>
