智慧医疗

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunWuKong_Hadoop/article/details/84546664
建档 性别 数量、占比
select count(CGRID),cxb,round(count(CGRID)/210880*100,2) from TBQYBASYXX group by cxb;

年龄段
SELECT
sum(case when n.nl>0 and n.nl<14 then n.count_id else null end)  q,
sum(case when n.nl>=14 and n.nl<=19 then n.count_id else null end)  a,
sum(case when n.nl>=20 and n.nl<=39 then n.count_id else null end)  z,
sum(case when n.nl>=40 and n.nl<=59 then n.count_id else null end) e,
sum(case when n.nl>=60 then n.count_id else null end) d from
(select substr(m.cbrnl,1,instr(m.cbrnl,'岁',-1)-1) as nl,m.count_id,m.zb from 
(
select count(CGRID) as count_id,cbrnl,round(count(CGRID)/210880*100,2) as zb from TBQYBASYXX group by cbrnl having cbrnl like '%岁%') m
)n;

分地区(spark)
select substring_index(substring_index(c.cjtzz,'+',4),'+',-1) as xz,count(1) from (
select b.cjtzz,b.csfzh
from lqioc_ioc_ods.TBQYBASYXX a
inner JOIN 
lqioc_ioc_ods.JKDAJBXXB  b
on a.csfzh=b.csfzh) c GROUP BY substring_index(substring_index(c.cjtzz,'+',4),'+',-1);


机构医生人数
select DISTINCT CYSMC,CJGMC from TBMZCFHZ;

年度门诊费用(分类)
select csfzl,sum(to_number(MYSJE_num)) as fy from (select csfzl,regexp_substr(MYSJE, '\d*(\d*\.\d*)?') as MYSJE_num  from TBMZFYMX)  GROUP BY csfzl;

年度住院费用(分类)
select csfzl,sum(to_number(MYSJE_num)) as fy from (select csfzl,regexp_substr(MYSJE, '\d*(\d*\.\d*)?') as MYSJE_num  from TBQYZYFYMX)  GROUP BY csfzl

门诊就诊人次
select count(1) from (
select CSFRMC,DJZRQ,count(1) from TBMZFYMX group by CSFRMC,DJZRQ);

住院就诊人次
select count(1) from (
select CXM,DLASTM,count(1) from TBQYZYFYMX group by CXM,DLASTM);

门诊就诊区域(spark)
select substring_index(substring_index(c.cjtzz,'+',4),'+',-1) as xz,count(1) from (
select a.CSFRMC,a.DJZRQ,b.cjtzz,b.csfzh
from lqioc_ioc_ods.TBMZFYMX a
inner JOIN 
lqioc_ioc_ods.JKDAJBXXB  b
on a.CBRID=b.CBRID) c GROUP BY substring_index(substring_index(c.cjtzz,'+',4),'+',-1);

住院就诊区域(spark)
select substring_index(substring_index(c.cjtzz,'+',4),'+',-1) as xz,count(1) from (
select a.CSFRMC,a.DJZRQ,b.cjtzz,b.csfzh
from lqioc_ioc_ods.TBQYZYFYMX a
inner JOIN 
lqioc_ioc_ods.JKDAJBXXB  b
on a.CBRID=b.CBRID) c GROUP BY substring_index(substring_index(c.cjtzz,'+',4),'+',-1);

门诊年龄分布(spark)
select 
sum(case when n.nl>0 and n.nl<14 then n.count_id else null end)  q,
sum(case when n.nl>=14 and n.nl<=19 then n.count_id else null end)  a,
sum(case when n.nl>=20 and n.nl<=39 then n.count_id else null end)  z,
sum(case when n.nl>=40 and n.nl<=59 then n.count_id else null end) e,
sum(case when n.nl>=60 then n.count_id else null end) d from
(select (2018-substr(c.csfzh,7,4)) as nl, count(1) as count_id from (
select a.CSFRMC,a.DJZRQ,b.cjtzz,b.csfzh
from lqioc_ioc_ods.TBMZFYMX a
inner JOIN 
lqioc_ioc_ods.JKDAJBXXB  b
on a.CBRID=b.CBRID) c GROUP BY (2018-substr(c.csfzh,7,4)))n;

住院年龄分布(spark)
select 
sum(case when n.nl>0 and n.nl<14 then n.count_id else null end)  q,
sum(case when n.nl>=14 and n.nl<=19 then n.count_id else null end)  a,
sum(case when n.nl>=20 and n.nl<=39 then n.count_id else null end)  z,
sum(case when n.nl>=40 and n.nl<=59 then n.count_id else null end) e,
sum(case when n.nl>=60 then n.count_id else null end) d from
(select (2018-substr(c.csfzh,7,4)) as nl, count(1) as count_id from (
select a.CSFRMC,a.DJZRQ,b.cjtzz,b.csfzh
from lqioc_ioc_ods.TBQYZYFYMX a
inner JOIN 
lqioc_ioc_ods.JKDAJBXXB  b
on a.CBRID=b.CBRID) c GROUP BY (2018-substr(c.csfzh,7,4)))n;

近6个月就诊量趋势 门诊
SELECT SUBSTR(C.DJZSJ,1,7) AS SY,count(1) FROM (SELECT CBRID,DJZSJ,COUNT(*) FROM TBMZJZXX GROUP BY CBRID,DJZSJ)C
group by SUBSTR(C.DJZSJ,1,7) order by SUBSTR(C.DJZSJ,1,7) desc;

近6个月就诊量趋势 紫住院
SELECT SUBSTR(C.DRYSJ,1,7) AS SY,count(1) FROM (SELECT CBRID,DRYSJ,COUNT(*) FROM TBQYZYBR GROUP BY CBRID,DRYSJ)C
group by SUBSTR(C.DRYSJ,1,7) order by SUBSTR(C.DRYSJ,1,7) desc;

年度门诊就诊量排名Top5
select SUBSTR(DJZSJ,1,4) AS SY,CJGID,CJGMC,COUNT(1) from TBMZJZXX GROUP BY SUBSTR(DJZSJ,1,4),CJGID,CJGMC ORDER BY COUNT(1) DESC;

年度住院就诊量排名Top5
select SUBSTR(A.DRYSJ,1,4) AS SY,A.CJGID,B.CJGMC,COUNT(1) AS COUNT_ID from TBQYZYBR  A 
LEFT JOIN
(SELECT DISTINCT CJGID,CJGMC FROM TBMZJZXX) B
ON A.CJGID=B.CJGID
GROUP BY SUBSTR(A.DRYSJ,1,4),A.CJGID,B.CJGMC ORDER BY SUBSTR(A.DRYSJ,1,4),COUNT(1) DESC;

年度健康体检量排名Top5
select SUBSTR(A.DJLSJ,1,4) AS SY,A.CJGID,B.CJGMC,COUNT(1) AS COUNT_ID from TBJKTJ A
LEFT JOIN
(SELECT DISTINCT CJGID,CJGMC FROM TBMZJZXX) B
ON A.CJGID=B.CJGID
GROUP BY SUBSTR(A.DJLSJ,1,4),A.CJGID,B.CJGMC ORDER BY SUBSTR(A.DJLSJ,1,4),COUNT(1) DESC;

门诊就诊疾病排名Top5
select SUBSTR(DZDSJ,1,7),CZDMC,COUNT(1) from TBQYMZZD group by SUBSTR(DZDSJ,1,7),CZDMC ORDER BY SUBSTR(DZDSJ,1,7),COUNT(1) desc;

住院就诊疾病排名Top5
select SUBSTR(DRYSJ,1,7),replace(CZYJBMC,to_char(chr(13))||to_char(chr(10)),''),COUNT(1) from TBQYZYBR group by SUBSTR(DRYSJ,1,7),replace(CZYJBMC,to_char(chr(13))||to_char(chr(10)),'') 
HAVING SUBSTR(DRYSJ,1,7)='2016-12'
ORDER BY SUBSTR(DRYSJ,1,7),COUNT(1) desc;

重点传染病情
select SUBSTR(DRYSJ,1,7),replace(CZYJBMC,to_char(chr(13))||to_char(chr(10)),''),COUNT(1)
from TBQYZYBR
group by SUBSTR(DRYSJ,1,7),replace(CZYJBMC,to_char(chr(13))||to_char(chr(10)),'') 
HAVING replace(CZYJBMC,to_char(chr(13))||to_char(chr(10)),'')
in
('流行性感冒',
'流行性腮腺炎',
'手足口病',
'结核病',
'肝炎',
'风疹')
ORDER BY SUBSTR(DRYSJ,1,7),COUNT(1) desc;

常见病门诊用药
select * from (
select a.CJBMC,b.CYPMC,count(1),row_number() over (partition by a.CJBMC order by count(1) desc) as px from  
lqioc_ioc_ods.TBMZCFHZ a 
right JOIN
lqioc_ioc_ods.MZCFMXTBMZCFMX b
ON a.CCFH=b.CCFH
group by a.CJBMC,b.CYPMC
having a.CJBMC
in ('流行性感冒',
'糖尿病',
'冠心病',
'慢性胃炎',
'上呼吸道感染',
'高血压')) c
where  c.px<30;

猜你喜欢

转载自blog.csdn.net/SunWuKong_Hadoop/article/details/84546664