• 用碑情况统计


    INSERT INTO BUSINESS_EX_INFO
    
    SELECT SEQ_BUSINESSEXINFO_ID.NEXTVAL,ID,16,'' FROM qtywb where (ywdm='12' OR YWDM='14') and zxflag<>'1';
    
    --用碑数据--
    
    SELECT ssrq, mx,sum(zys) as zys,sum(jgs) as jgs,sum(BQTWYBS) as BQTWYBS,sum(BQTYYBS) as BQTYYBS,sum(BQTMS) as BQTMS,sum(FBQTWYBS) as FBQTWYBS,sum(FBQTYYBS) as FBQTYYBS,sum(FBQTMS) as FBQTMS FROM (
    --租用--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,count(*) AS ZYS,0 AS JGS,0 AS BQTWYBS,0 AS BQTYYBS,0 AS BQTMS,0 AS FBQTWYBS,0 AS FBQTYYBS,0 AS FBQTMS FROM ywdjb WHERE zxflag<>'1' AND to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30' GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --旧墓改造--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,count(*),0,0,0,0,0,0 FROM qtywb WHERE zxflag<>'1' AND ywdm='14' AND to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30' GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --本期退--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,0,0,0,count(*),0,0,0 FROM qtywb t1 WHERE zxflag<>'1' AND ywdm='12' AND djh IN(SELECT djh FROM ywdjb WHERE t1.djh=djh and to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30') GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --非本期退--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,0,0,0,0,0,0,count(*) FROM qtywb t1 WHERE zxflag<>'1' AND ywdm='12' AND djh NOT IN(SELECT djh FROM ywdjb WHERE t1.djh=djh and to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30') GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --本期退未用碑数--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,0,count(*),0,0,0,0,0 FROM qtywb t1,BUSINESS_EX_INFO t2 WHERE t1.zxflag<>'1' AND t1.ywdm='12' and t2.BUSINESS_ID=t1.id and PROPERTY_ID=16 and PROPERTY_VALUE='' AND DJH IN(SELECT djh FROM ywdjb WHERE t1.djh=djh and to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30') GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --本期退已用碑数--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,count(*),0,0,0,0,0,0 FROM qtywb t1,BUSINESS_EX_INFO t2 WHERE t1.zxflag<>'1' AND t1.ywdm='12' and t2.BUSINESS_ID=t1.id and PROPERTY_ID=16 and PROPERTY_VALUE='' AND DJH IN(SELECT djh FROM ywdjb WHERE t1.djh=djh and to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30') GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --非本期退未用碑数--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,0,0,0,0,count(*),0,0 FROM qtywb t1,BUSINESS_EX_INFO t2 WHERE t1.zxflag<>'1' AND t1.ywdm='12' and t2.BUSINESS_ID=t1.id and PROPERTY_ID=16 and PROPERTY_VALUE='' AND DJH NOT IN(SELECT djh FROM ywdjb WHERE t1.djh=djh and to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30') GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    UNION ALL
    --非本期退已用碑数--
    SELECT TO_CHAR(rq,'yyyymm') as ssrq,mxmc as mx,0,0,0,0,0,0,count(*),0 FROM qtywb t1,BUSINESS_EX_INFO t2 WHERE t1.zxflag<>'1' AND t1.ywdm='12' and t2.BUSINESS_ID=t1.id and PROPERTY_ID=16 and PROPERTY_VALUE='' AND DJH NOT IN(SELECT djh FROM ywdjb WHERE t1.djh=djh and to_char(rq,'yyyy-mm-dd')>='1900-05-26' AND to_char(rq,'yyyy-mm-dd')<='2016-06-30') GROUP BY mxmc,TO_CHAR(rq,'yyyymm')
    
    ) group by mx,ssrq;
  • 相关阅读:
    联合查询
    单表查询
    表和表之间的关系
    mysql完整性约束
    mysql 数据类型
    DRBD 数据镜像软件
    Memcached
    Redis
    SVN版本控制服务
    大数据hadoop分布式系统
  • 原文地址:https://www.cnblogs.com/siyunianhua/p/5627131.html
Copyright © 2020-2023  润新知