<?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.unis.visualization.modular.grainSituationDetection.mapper.GrainSituationDetectionMapper">

    <select id="getDepotStockLqChartDatas" resultType="com.unis.visualization.modular.grainSituationDetection.entity.VO.GrainSituationDetectionChart">
         SELECT
            a.org_id,
            a.org_name,
            a.longitude,
            a.latitude,
            b.temp_max,
            b.temp_min,
            b.temp_avg,
            ROUND(IFNULL(SUM(kcsl),0.0)/1000/10000,2) as kcsl
            FROM
            depot_qh.org_info a
            LEFT JOIN
            (SELECT org_id,temp_max,temp_min,temp_avg
                FROM (
                        SELECT org_id,temp_max,temp_min,temp_avg,
                                     ROW_NUMBER() OVER (PARTITION BY org_id ORDER BY gather_time DESC) AS rn
                        FROM depot_qh.t_lq_data
                ) t
                WHERE rn = 1
            )
             b on a.org_id = b.org_id
            LEFT JOIN depot_qh.data_kcgl_kcsw_default c on a.org_id = c.UnitID
            where a.org_id != '9'
            GROUP BY a.org_id
            ORDER BY a.org_id
    </select>
</mapper>