<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tofly.xrtygis.custom.mapper.TableCountMapper">

    <select id="getPartition" resultType="map">
        select id, dma_name, partition_level, sum(in_num) in_num, sum(out_num) out_num
        from (select a.id,
                     a.dma_name,
                     partition_level,
                     decode(isout, 0, count(0), 0) in_num,
                     decode(isout, 1, count(0), 0) out_num
              from tf_ywpn_dmaregion_w a,
                   tf_ywpn_dmaandobser_w b
              where a.id = b.dma_id
              group by a.id, dma_name, isout, partition_level
             ) t
        group by id, dma_name, partition_level
        order by partition_level
    </select>

    <select id="getPartitionInfo" resultType="map">
        select dma_name,
               decode(isout, '0', '入口', 1, '出口') inout,
               sch_name,
               sch,
               a.factory,
               a.phenotype,
               a.bore,
               decode(a.isflow,'0','不参与','1','参与') isflow,
               decode(a.ispress,'0','不采集','1','采集') ispress
        from TF_YWPN_DMATABLE_W a,
             tf_ywpn_dmaandobser_w b,
             tf_ywpn_dmaregion_w c
        where a.id = b.table_id
          and b.dma_id = c.id
          and dma_id = #{dmaId}
        order by isout
    </select>

    <select id="viewPartitionInfo" resultType="map">
        select dma_name,
               decode(isout, '0', '入口', '1', '出口') inout,
               sch_name,
               sch,
               a.factory,
               a.phenotype,
               a.bore,
               decode(a.isflow,'0','不参与','1','参与') isflow,
               decode(a.ispress,'0','不采集','1','采集') ispress
        from TF_YWPN_DMATABLE_W a,
             tf_ywpn_dmaandobser_w b,
             tf_ywpn_dmaregion_w c
        where a.id = b.table_id
          and b.dma_id = c.id
          and dma_id = #{dmaId}
        order by isout
    </select>

</mapper>