用碑情况统计

复制代码
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;
复制代码

 

posted @   韩梦芫  阅读(202)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示