<?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.circulateMonitor.modular.realTimeQueryStatisticItem.mapper.RealTimeQueryStatisticItemMapper">
    <select id="selectOneConvert" parameterType="string" resultType="com.unis.circulateMonitor.modular.realTimeQueryStatisticItem.param.RealTimeQueryStatisticItemConvertParam">
        SELECT
            t1.xmPrice,
            t1.qkPrice,
            t1.dgPrice,
            t1.dmPrice,
            t1.bmPrice,
            t1.czyPrice,
            t2.xmTradeQuantity,
            t2.qkTradeQuantity,
            t2.dgTradeQuantity,
            t2.dmTradeQuantity,
            t2.bmTradeQuantity,
            t2.czyTradeQuantity
        FROM(
        SELECT
                cm_real_time_query_statistic_id,
            SUM(CASE grain_variety WHEN 1 THEN price ELSE 0 END) as xmPrice,
            SUM(CASE grain_variety WHEN 2 THEN price ELSE 0 END) as qkPrice,
            SUM(CASE grain_variety WHEN 3 THEN price ELSE 0 END) as dgPrice,
            SUM(CASE grain_variety WHEN 4 THEN price ELSE 0 END) as dmPrice,
            SUM(CASE grain_variety WHEN 5 THEN price ELSE 0 END) as bmPrice,
            SUM(CASE grain_variety WHEN 6 THEN price ELSE 0 END) as czyPrice
        FROM biz_cm_real_time_query_statistic_item
        WHERE cm_real_time_query_statistic_id = #{id}
        ) t1
        LEFT JOIN
        (
        SELECT
                cm_real_time_query_statistic_id,
            SUM(CASE grain_variety WHEN 1 THEN trade_quantity ELSE 0 END) as xmTradeQuantity,
            SUM(CASE grain_variety WHEN 2 THEN trade_quantity ELSE 0 END) as qkTradeQuantity,
            SUM(CASE grain_variety WHEN 3 THEN trade_quantity ELSE 0 END) as dgTradeQuantity,
            SUM(CASE grain_variety WHEN 4 THEN trade_quantity ELSE 0 END) as dmTradeQuantity,
            SUM(CASE grain_variety WHEN 5 THEN trade_quantity ELSE 0 END) as bmTradeQuantity,
            SUM(CASE grain_variety WHEN 6 THEN trade_quantity ELSE 0 END) as czyTradeQuantity
        FROM biz_cm_real_time_query_statistic_item
        WHERE cm_real_time_query_statistic_id = #{id}
        ) t2 ON t1.cm_real_time_query_statistic_id = t2.cm_real_time_query_statistic_id
    </select>
</mapper>