机构服务统计sql

  1 SELECT UO.ORG_NAME ORGNAME, A.QYS, B.LNTJS, C.XJDAS, D.DASYS, E.GXYSFS, F.TNBSFS,G.HGDAS, H.GXYGLS, I.GXYGFS, J.TNBGLS, K.TNBGFS
  2   FROM UMS_ORG UO
  3   LEFT JOIN (/*新增家医服务签约*/
  4              SELECT EB.MNG_ORG_CODE ORG_CODE, COUNT(DISTINCT EB.EHR_ID) QYS
  5                FROM FDS_CONTRACT FC, EHR_BASE EB
  6               WHERE FC.SIGN_FAMILY_ID = EB.FAMILY_ID
  7                 AND FC.CONTRACT_STATE = ‘2‘
  8                 AND FC.SIGN_DATE >= TO_DATE(‘2015-01-01‘,‘YYYY-MM-DD‘)
  9                 AND FC.SIGN_DATE <= TO_DATE(‘2015-03-30‘,‘YYYY-MM-DD‘)
 10                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 11               GROUP BY EB.MNG_ORG_CODE) A
 12     ON UO.ORG_CODE = A.ORG_CODE
 13   LEFT JOIN (/*65岁以上老人免费体检*/
 14              SELECT EB.MNG_ORG_CODE ORG_CODE,
 15                      COUNT(DISTINCT EB.EHR_ID) LNTJS
 16                FROM EHR_BASE EB, SVC_EXAM_1 SE
 17               WHERE EB.EHR_ID = SE.EHR_ID
 18                 AND SE.TP_OLD = ‘1‘
 19                 AND SE.EXAM_DATE >= TO_DATE(‘2015-01-01‘,‘YYYY-MM-DD‘)
 20                 AND SE.EXAM_DATE <= TO_DATE(‘2015-03-30‘,‘YYYY-MM-DD‘)
 21                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 22               GROUP BY EB.MNG_ORG_CODE) B
 23     ON UO.ORG_CODE = B.ORG_CODE
 24   LEFT JOIN (/*新建健康档案*/
 25              SELECT EB.MNG_ORG_CODE ORG_CODE,
 26                      COUNT(1) XJDAS
 27                FROM EHR_BASE EB
 28               WHERE EB.DATE_CREATED >= TO_DATE(‘2015-01-01‘,‘YYYY-MM-DD‘)
 29                 AND EB.DATE_CREATED <= TO_DATE(‘2015-03-30‘,‘YYYY-MM-DD‘)
 30                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 31               GROUP BY EB.MNG_ORG_CODE) C
 32     ON UO.ORG_CODE = C.ORG_CODE
 33   LEFT JOIN (/*健康档案使用*/
 34              SELECT EB.MNG_ORG_CODE ORG_CODE,
 35                      COUNT(1) DASYS
 36                FROM EHR_BASE EB
 37               WHERE EB.LAST_MNG_DATE > ADD_MONTHS(SYSDATE, -12)
 38                 AND EB.LAST_MNG_DATE <= SYSDATE
 39                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 40               GROUP BY EB.MNG_ORG_CODE) D
 41     ON UO.ORG_CODE = D.ORG_CODE
 42   LEFT JOIN (/*高血压患者随访*/
 43              SELECT EB.MNG_ORG_CODE ORG_CODE,
 44                      COUNT(DISTINCT EB.EHR_ID) GXYSFS
 45                FROM EHR_BASE EB, SVC_FLW_CHRONIC SFC
 46               WHERE EB.EHR_ID = SFC.EHR_ID
 47                 AND SFC.CHRONIC_TYPE IN (‘1‘, ‘3‘)
 48                 AND SFC.DATE_CREATED >= TO_DATE(‘2015-01-01‘,‘YYYY-MM-DD‘)
 49                 AND SFC.DATE_CREATED <= TO_DATE(‘2015-03-30‘,‘YYYY-MM-DD‘)
 50                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 51               GROUP BY EB.MNG_ORG_CODE) E
 52     ON UO.ORG_CODE = E.ORG_CODE
 53   LEFT JOIN (/*2型糖尿病随访*/
 54              SELECT EB.MNG_ORG_CODE ORG_CODE,
 55                      COUNT(DISTINCT EB.EHR_ID) TNBSFS
 56                FROM EHR_BASE EB, SVC_FLW_CHRONIC SFC
 57               WHERE EB.EHR_ID = SFC.EHR_ID
 58                 AND SFC.CHRONIC_TYPE IN (‘2‘, ‘3‘)
 59                 AND SFC.DATE_CREATED >= TO_DATE(‘2015-01-01‘,‘YYYY-MM-DD‘)
 60                 AND SFC.DATE_CREATED <= TO_DATE(‘2015-03-30‘,‘YYYY-MM-DD‘)
 61                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 62               GROUP BY EB.MNG_ORG_CODE) F
 63     ON UO.ORG_CODE = F.ORG_CODE
 64   LEFT JOIN (/*合格健康档案数*/
 65              SELECT EB.MNG_ORG_CODE ORG_CODE,
 66                      COUNT(1) HGDAS
 67                FROM EHR_BASE EB
 68               WHERE EB.FILE_SPECIFICATION = ‘1‘
 69                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
 70                 AND EB.DEATH = ‘1‘
 71                 AND EB.CANCELLED = ‘1‘
 72                 AND EB.MOVED_OUT = ‘1‘
 73               GROUP BY EB.MNG_ORG_CODE) G
 74     ON UO.ORG_CODE = G.ORG_CODE
 75   LEFT JOIN (/*社区机构管理的高血压人数*/
 76              SELECT EB.MNG_ORG_CODE ORG_CODE,
 77                      COUNT(1) GXYGLS
 78                FROM EHR_BASE EB
 79               WHERE EB.CD_HYPERTENSION = ‘1‘
 80                 AND EB.LAST_MNG_DATE > ADD_MONTHS(SYSDATE, -12)
 81                 AND EB.LAST_MNG_DATE <= SYSDATE
 82                 AND EB.DEATH = ‘1‘
 83                 AND EB.CANCELLED = ‘1‘
 84                 AND EB.MOVED_OUT = ‘1‘
 85               GROUP BY EB.MNG_ORG_CODE) H
 86     ON UO.ORG_CODE = H.ORG_CODE
 87   LEFT JOIN (/*高血压规范管理人数*/
 88              SELECT EB.MNG_ORG_CODE ORG_CODE,
 89                      COUNT(DISTINCT SFC.EHR_ID) GXYGFS
 90                FROM EHR_BASE EB
 91               INNER JOIN (SELECT EHR_ID
 92                             FROM SVC_FLW_CHRONIC
 93                            WHERE DATE_CREATED > ADD_MONTHS(SYSDATE, -12)
 94                              AND DATE_CREATED <= SYSDATE
 95                              AND CHRONIC_TYPE IN (‘1‘, ‘3‘)
 96                              AND FLW_ORG_CODE LIKE ‘0203%‘
 97                            GROUP BY EHR_ID
 98                           HAVING COUNT(EHR_ID) = 4) SFC
 99                  ON EB.EHR_ID = SFC.EHR_ID
100               WHERE EB.CD_HYPERTENSION = ‘1‘
101                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
102                 AND EB.DEATH = ‘1‘
103                 AND EB.CANCELLED = ‘1‘
104                 AND EB.MOVED_OUT = ‘1‘
105               GROUP BY EB.MNG_ORG_CODE) I
106     ON UO.ORG_CODE = I.ORG_CODE
107   LEFT JOIN (/*社区机构管理的糖尿病人数*/
108              SELECT EB.MNG_ORG_CODE ORG_CODE,
109                      COUNT(1) TNBGLS
110                FROM EHR_BASE EB
111               WHERE EB.CD_DIABETES_MELLITUS = ‘1‘
112                 AND EB.LAST_MNG_DATE > ADD_MONTHS(SYSDATE, -12)
113                 AND EB.LAST_MNG_DATE <= SYSDATE
114                 AND EB.DEATH = ‘1‘
115                 AND EB.CANCELLED = ‘1‘
116                 AND EB.MOVED_OUT = ‘1‘
117               GROUP BY EB.MNG_ORG_CODE) J
118     ON UO.ORG_CODE = J.ORG_CODE
119   LEFT JOIN (/*糖尿病规范管理人数*/
120              SELECT EB.MNG_ORG_CODE ORG_CODE,
121                      COUNT(DISTINCT SFC.EHR_ID) TNBGFS
122                FROM EHR_BASE EB
123               INNER JOIN (SELECT EHR_ID
124                             FROM SVC_FLW_CHRONIC
125                            WHERE DATE_CREATED > ADD_MONTHS(SYSDATE, -12)
126                              AND DATE_CREATED <= SYSDATE
127                              AND CHRONIC_TYPE IN (‘2‘, ‘3‘)
128                              AND FLW_ORG_CODE LIKE ‘0203%‘
129                            GROUP BY EHR_ID
130                           HAVING COUNT(EHR_ID) = 4) SFC
131                  ON EB.EHR_ID = SFC.EHR_ID
132               WHERE EB.CD_DIABETES_MELLITUS = ‘1‘
133                 AND EB.MNG_ORG_CODE LIKE ‘0203%‘
134                 AND EB.DEATH = ‘1‘
135                 AND EB.CANCELLED = ‘1‘
136                 AND EB.MOVED_OUT = ‘1‘
137               GROUP BY EB.MNG_ORG_CODE) K
138     ON UO.ORG_CODE = K.ORG_CODE
139  WHERE UO.ORG_CODE LIKE ‘0203%‘
140  ORDER BY UO.ORG_CODE

时间: 2024-10-05 14:49:00

机构服务统计sql的相关文章

综合查询各项服务统计sql整理

1 ----------------------------------------------------------------------------------------- 2 /* 3 综合查询: 4 查询条件: 5 1:管理机构(包含下级):新街口街道赵登禹路社区卫生服务站 6 2:慢病分类(包含或):高血压 7 查询结果:1862 8 */ 9 SELECT COUNT(*) 10 FROM ( 11 SELECT 12 EB.ID, 13 EB.EHR_ID, 14 EB.PE

统计sql语句执行效率

--统计sql语句执行效率SELECT (total_elapsed_time / execution_count)/1000 N'平均时间ms' ,total_elapsed_time/1000 N'总花费时间ms' ,total_worker_time/1000 N'所用的CPU总时间ms' ,total_physical_reads N'物理读取总次数' ,total_logical_reads/execution_count N'每次逻辑读次数' ,total_logical_reads

Oracle EBS-SQL (PO-16):检查采购订单完成情况统计.sql

select         e.FULL_NAME                                                     采购员,         sum(plla.quantity-plla.QUANTITY_CANCELLED)  订购数量,         sum(plla.Quantity_Received)                           完成数量 ,         round(SUM(plla.Quantity_Receive

统计SQL语句耗时百分比

-- sql语句耗时百分比 declare @tmptb table(id int,name varchar(50),total_worker_time bigint,rate varchar(50),execute_count bigint) ;with cte1 as(select a.*,t.*from sys.dm_exec_query_stats across apply sys.dm_exec_sql_text(a.plan_handle) twhere t.dbid >= 5 ),

使用Windows Azure Blob 存储服务进行 SQL Server 备份和还原

好处: 1.灵活.可靠.无限制, 安全的站点外存储 2.即时.高度可用.耐久的备份存档方案. 3.仅对使用的服务付费.可以作为经济合算的站点外备份存档方案. 对于 Windows Azure Blob 存储服务的 SQL Server 备份支持是 SQL Server 2012 SP1 CU2 增强功能,当然sql server 2014也是可以的. 第 1 课:创建 Windows Azure 存储对象 步骤: 1.创建 Windows Azure 存储帐户和 Blob 容器. 创建存储账户,

统计Sql Server数据库中的每张表的记录数

统计Sql Server数据库中的每张表的记录数 USE JYDB                   -- JYDB为你所在的数据库 GO select b.[name] '表名',max(a.rowcnt) '记录数'   from sysindexes a   join sys.objects b on b.object_id=a.id   where b.type='U'   group by b.[name]

检测机构服务平台之实验室设计装修要求

实验室设计装修的过程中我们有哪些需要注意的呢,不同的实验室有不同的要求,对此很多人不是很了解,下面跟着检测机构服务平台的脚步一起来看看吧!? 一.实验室的分类及职责:? 实验室就是分析检验实验室,检测机构服务平台总结告诉大家在学校.工厂.科研院等不同场所有不同的性质. 学校的化验室一类是为学生进行分析化学实验用的教学基地,另一类是为科研服务的亦兼有科研性质的分析化学研究室. 工厂设中央化验室.车间化验室等.车间化验室主要担负生产过程中成品.半成品的控制分析.中央化验室主要担负原料分析.产品质量检

MySQL分段统计SQL写法 与 Mybatis 报错:java.math.BigDecimal cannot be cast to java.lang.Integer

mysql> select -> sum(case when score<60 then 1 else 0 end) as '<60', -> sum(case when score>=60 and score<=69 then 1 else 0 end) as '60~69', -> sum(case when score>=70 and score<=79 then 1 else 0 end) as '70~79', -> sum(ca

用料统计SQL

Itpub上遇到一个求助写SQL的帖子,感觉很有意思,于是写出来看看,要求如下: 有个计划表1, 记录物料的年度计划量 有个实际使用情况表2,记录实际使用情况. 最后要出个统计表,把计划和实际的数据结合到一起进行统计, 有特殊的情况就是可能部分物料有计划但是没有实际使用,有的物料无计划但是有实际使用情况, 要把这些数据合并到一起按照季度进行统计并算差异量,能实现吗?? 于是建表插数据,表结构如下: create table plan(OBJ varchar2(10),YEAR number(4)