文章目录

  • 一、序号导表

    • 1.首字母排序
    • 2.按序号输出
      • (1)递增序号
      • (2)按照机构递增序号
  • 二、原始库与档案库数据转移量对比
  • 三、原始库数据汇总显示(+往年数据对比)
  • 四、2021机构进度查询
  • 总结

一、序号导表

1、设置姓名按照汉字首字母排序,使用强制转换 (转换编码) convert(xm using gbk)。


select  (@i:=@i+1) as '序号',tjrq  '体检日期',org_name '机构',xm '姓名',sfz '身份证',
concat(SUBSTRING(sfz FROM 7 FOR 4) ,'-',SUBSTRING(sfz FROM 11 FOR 2),'-',SUBSTRING(sfz FROM 13 FOR 2)) '出生日期',
case when gender=1 then '男' else '女'end '性别',lxdh '联系电话'from health_record2021.mh_lnr_jkda,(SELECT @i:=0)  as i
where org_id like '37110212%' and tjrq BETWEEN '20210401' and '20210430' and is_fufei=0
ORDER by convert(xm using gbk) asc;

2、设置记录按照序号输出:

(1)添加递增的序号列。

select (@i:=@i+1) as i,a.* from mh_lnr_jkda a,(select @i:=0) as i 

(2)按照机构设置递增序号列。

select RANK '序号',tjrq  '体检日期',org_name '机构',xm '姓名',sfz '身份证',
concat(SUBSTRING(sfz FROM 7 FOR 4) ,'-',SUBSTRING(sfz FROM 11 FOR 2),'-',SUBSTRING(sfz FROM 13 FOR 2)) '出生日期',age '年龄',
case when gender=1 then '男' else '女'end '性别',lxdh '联系电话',address '地址'
from
(select mh_lnr_jkda_A.*, @rank:=if(@ORG_NAME = ORG_NAME,@rank + 1, 1) as  rank, @ORG_NAME:=ORG_name  from
(SELECT * FROM MH_LNR_JKDA WHERE ORG_ID LIKE'37110212%') MH_LNR_JKDA_A,
(select @rank:=0,@ORG_NAME:=null) a   order by ORG_NAME,ry_type) a
where org_id like '37110212%' and tjrq BETWEEN '20210401' and '20210430'
ORDER BY tjrq,org_name

二、原始库与档案库数据转移量对比。

set @org_id=50011301; -- 机构号
set @start_time=20211026; -- 开始时间
set @end_time=20211026; -- 结束时间-- 整体对比查询各项目人数select '报告总人数' as '项目',COUNT(1) as '数量'  from health_info2021.mh_jktj j  where j.org_id like concat(@org_id,'%') and j.tjrq >=@start_time and j.tjrq <=@end_time  and j.is_fufei=0  UNION ALL
select '档案——总人数' as '项目',COUNT(1) as '档案数量'  from health_record2021.mh_lnr_jkda   where  org_id like concat(@org_id,'%') and  tjrq >=@start_time and tjrq <=@end_time
union all
select '报告中医体质' as '项目',COUNT(*) as '报告中医数量'  from health_info2021.mh_zytz where org_id like concat(@org_id,'%') and tbrq >=@start_time and tbrq <=@end_time
union all
select '档案——中医体质' as '项目',COUNT(*) as '档案中医数量'  from health_record2021.mh_zytz where org_id like concat(@org_id,'%') and tbrq >=@start_time and tbrq <=@end_time
union ALL
select '报告基本信息' as '项目',COUNT(1) as '报告基本信息数量' from basicinfo.rhr where mh_card in (select mh_card from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0)
union ALL
select '档案——基本信息' as '项目',COUNT(1) as '档案基本信息数量' from health_record2021.mh_grjbxx where mh_card in (select mh_card from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time)  UNION ALL
select '报告生化人数' as '项目',COUNT(1) as '报告生化数量' from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 1
UNION ALL
select '档案——生化人数' as '项目',COUNT(1) as '档案生化数量' from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 1UNION ALL
select '报告生化小项' as '项目',COUNT(*) as '报告生化小项' from health_info2021.mh_jy_result where jy_parid in(select jy_parid from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 1)
union all
select '档案——生化小项' as '项目',COUNT(*) as '档案生化小项' from health_record2021.mh_jy_result where jy_parid in(select jy_parid from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 1)UNION ALL
select '报告尿检人数' as '项目',COUNT(1) as '报告尿检数量' from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 5
union all
select '档案——尿检人数' as '项目',COUNT(1) as '档案尿检数量' from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 5
UNION ALL
select '报告尿检小项' as '项目',COUNT(*) as '报告尿小项数量' from health_info2021.mh_jy_result where jy_parid in(select jy_parid from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 5)
union all
select '档案——尿检小项' as '项目',COUNT(*) as '档案尿小项数量' from health_record2021.mh_jy_result where jy_parid in(select jy_parid from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 5)
UNION ALL
select '报告血球人数' as '项目',COUNT(1) as '报告血球数量' from health_info2021.mh_jy_xqparson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0)
union all
select '档案——血球人数' as '项目',COUNT(1) as '档案血球数量' from health_record2021.mh_jy_xqparson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time)
UNION ALL
select '报告血球小项' as '项目',COUNT(*) as '报告血球小项' from health_info2021.mh_jy_xqresult where xq_parid in(select xq_parid from health_info2021.mh_jy_xqparson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0))
union all
select '档案——血球小项' as '项目',COUNT(*) as '档案血球小项' from health_record2021.mh_jy_xqresult where xq_parid in(select xq_parid from health_record2021.mh_jy_xqparson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time))
union ALL
select '报告用药人数' as '项目',COUNT(DISTINCT jktj_id) as '报告用药数量' from health_info2021.mh_jktj_medicine where jktj_id in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0)
union all
select '档案——用药人数' as '项目',count(1) as '档案用药数量' from health_record2021.mh_lnr_jkda  where   org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time  and zyyyqk is not null and zyyyqk <>'无'and zyyyqk<>''
union ALL
select '报告用药人数小项' as '项目',COUNT(1) as '报告用药小项' from health_info2021.mh_jktj_medicine where jktj_id in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0)
union all
select '档案——用药小项' as '项目',sum(LENGTH(zyyyqk)-LENGTH(replace((zyyyqk),';',''))) as '档案用药小项' from health_record2021.mh_lnr_jkda  where   org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time  and zyyyqk is not null and zyyyqk <>'无'and zyyyqk<>'';-- 对比生化及各项人数
select '报告总人数' as '项目',COUNT(1) as '数量'  from health_info2021.mh_jktj j  where j.org_id like concat(@org_id,'%') and j.tjrq >=@start_time and j.tjrq <=@end_time   and is_fufei=0 UNION ALL
select '档案——总人数' as '项目',COUNT(1) as '档案数量'  from health_record2021.mh_lnr_jkda   where  org_id like concat(@org_id,'%') and  tjrq >=@start_time and tjrq <=@end_time
union ALL
select '报告生化人数' as '项目',COUNT(1) as '报告生化数量' from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 1
union ALL
select '档案——生化人数' as '项目',COUNT(1) as '档案生化数量' from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 1UNION ALL
select '报告生化小项' as '项目',COUNT(*) as '报告生化小项' from health_info2021.mh_jy_result where jy_parid in(select jy_parid from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 1)
union all
select '档案——生化小项' as '项目',COUNT(*) as '档案生化小项' from health_record2021.mh_jy_result where jy_parid in(select jy_parid from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 1)
union all
select concat('报告-',IFNULL(item_name,''),IFNULL(item_code,'')) as '项目',COUNT(*) as '报告生化小项' from health_info2021.mh_jy_result where jy_parid in(select jy_parid from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 1) GROUP BY item_code
union ALL
select concat('档案————',IFNULL(item_name,''),IFNULL(item_code,''))as '项目',COUNT(*) as '档案生化小项' from health_record2021.mh_jy_result where jy_parid in(select jy_parid from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 1)GROUP BY item_code;-- 对比血球人数
select '报告总人数' as '项目',COUNT(1) as '数量'  from health_info2021.mh_jktj j  where j.org_id like concat(@org_id,'%') and j.tjrq >=@start_time and j.tjrq <=@end_time  and is_fufei=0 UNION ALL
select '档案——总人数' as '项目',COUNT(1) as '档案数量'  from health_record2021.mh_lnr_jkda   where  org_id like concat(@org_id,'%') and  tjrq >=@start_time and tjrq <=@end_time
union ALL
select '报告血球人数' as '项目',COUNT(1) as '报告血球数量' from health_info2021.mh_jy_xqparson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0)
union ALL
select '档案——血球人数' as '项目',COUNT(1) as '档案血球数量' from health_record2021.mh_jy_xqparson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) UNION ALL
select '报告血球小项' as '项目',COUNT(*) as '报告血球数量' from health_info2021.mh_jy_xqresult where xq_parid in(select xq_parid from health_info2021.mh_jy_xqparson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0))
union all
select '档案——血球小项' as '项目',COUNT(*) as '档案血球小项' from health_record2021.mh_jy_xqresult where xq_parid in(select xq_parid from health_record2021.mh_jy_xqparson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time))
union all
select concat('报告-',IFNULL(item_name,''),IFNULL(item_code,'')) as '项目',COUNT(*) as '报告血球小项' from health_info2021.mh_jy_xqresult where xq_parid in(select xq_parid from health_info2021.mh_jy_xqparson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0)  ) GROUP BY item_code
union ALL
select concat('档案————',IFNULL(item_name,''),IFNULL(item_code,''))as '项目',COUNT(*) as '档案血球小项' from health_record2021.mh_jy_xqresult where xq_parid in(select xq_parid from health_record2021.mh_jy_xqparson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time)  )GROUP BY item_code  ;-- 对比尿检及各项人数
select '报告总人数' as '项目',COUNT(1) as '数量'  from health_info2021.mh_jktj j  where j.org_id like concat(@org_id,'%') and j.tjrq >=@start_time and j.tjrq <=@end_time  and is_fufei=0  UNION ALL
select '档案——总人数' as '项目',COUNT(1) as '档案数量'  from health_record2021.mh_lnr_jkda   where  org_id like concat(@org_id,'%') and  tjrq >=@start_time and tjrq <=@end_time
union ALL
select '报告尿检人数' as '项目',COUNT(1) as '报告尿检数量' from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 5
union ALL
select '档案——尿检人数' as '项目',COUNT(1) as '档案尿检数量' from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 5UNION ALL
select '报告尿检小项' as '项目',COUNT(*) as '报告尿小项数量' from health_info2021.mh_jy_result where jy_parid in(select jy_parid from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 5)
union all
select '档案——尿检小项' as '项目',COUNT(*) as '档案尿小项数量' from health_record2021.mh_jy_result where jy_parid in(select jy_parid from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 5)
union all
select concat('报告-',IFNULL(item_name,''),IFNULL(item_code,'')) as '项目',COUNT(*) as '报告生化小项' from health_info2021.mh_jy_result where jy_parid in(select jy_parid from health_info2021.mh_jy_parson where tjid in (select id from health_info2021.mh_jktj where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time and is_fufei=0) and jytype = 5) GROUP BY item_code
union ALL
select concat('档案————',IFNULL(item_name,''),IFNULL(item_code,''))as '项目',COUNT(*) as '档案生化小项' from health_record2021.mh_jy_result where jy_parid in(select jy_parid from health_record2021.mh_jy_parson where tjid in (select id from health_record2021.mh_lnr_jkda where org_id like concat(@org_id,'%') and tjrq >=@start_time and tjrq <=@end_time) and jytype = 5)GROUP BY item_code;

三、原始库数据汇总显示(+往年数据对比)

SET @org_id = 37232808;-- 机构号
SET @start_time = 20210101;-- 开始时间
SET @end_time = 20211231;-- 结束时间SELECTb.name,sh.*, xq.*, nj.*, j.*,yaowu.`用药情况`,2021档案.*
FROMmh_lnr_jktj j
join health_info2020.mh_lnr_jktj 2020体检 on j.mh_card=2020体检.mh_card
#join health_info2019.mh_lnr_jktj 2019体检 on j.mh_card=2019体检.mh_card
join health_record2021.mh_lnr_jkda 2021档案 on j.mh_card=2021档案.mh_card
join health_record2021.organization b on LEFT(j.org_id,8)=b.org_id
LEFT JOIN mh_jy_parson sp ON j.id = sp.tjid
AND sp.jytype = 1
LEFT JOIN (SELECTjy_parid,sum(IF (item_code = 'ALT',item_value,NULL)) '血清谷丙转氨酶',grouP_concat(IF (item_code = 'ALT',item_flag,NULL)) '血清谷丙结论',grouP_concat(IF (item_code = 'ALT',item_limit,NULL)) '血清谷丙范围',sum(IF (item_code = 'AST',item_value,NULL)) '血清谷草转氨酶',grouP_concat(IF (item_code = 'AST',item_flag,NULL)) '血清谷草结论',grouP_concat(IF (item_code = 'AST',item_limit,NULL)) '血清谷草范围',sum(IF (item_code = 'TBIL',item_value,NULL)) '总胆红素',grouP_concat(IF (item_code = 'TBIL',item_flag,NULL)) '总胆红素结论',grouP_concat(IF (item_code = 'TBIL',item_limit,NULL)) '总胆红素范围',sum(IF (item_code = 'CRE',item_value,NULL)) '血清肌酐',grouP_concat(IF (item_code = 'CRE',item_flag,NULL)) '肌酐结论',grouP_concat(IF (item_code = 'CRE',item_limit,NULL)) '肌酐范围',sum(IF (item_code = 'UREA',item_value,NULL)) '血尿素氮',grouP_concat(IF (item_code = 'UREA',item_flag,NULL)) '尿素氮结论',grouP_concat(IF (item_code = 'UREA',item_limit,NULL)) '尿素氮范围',sum(IF (item_code = 'TC',item_value,NULL)) '总胆固醇',grouP_concat(IF (item_code = 'TC',item_flag,NULL)) '总胆固醇结论',grouP_concat(IF (item_code = 'TC',item_limit,NULL)) '总胆固醇范围',sum(IF (item_code = 'TG',item_value,NULL)) '甘油三酯',grouP_concat(IF (item_code = 'TG',item_flag,NULL)) '甘油三脂结论',grouP_concat(IF (item_code = 'TG',item_limit,NULL)) '甘油三酯范围',sum(IF (item_code = 'LDL-C',item_value,NULL)) '低密度脂蛋白胆固醇',grouP_concat(IF (item_code = 'LDL-C',item_flag,NULL)) '低密结论',grouP_concat(IF (item_code = 'LDL-C',item_limit,NULL)) '低密范围',sum(IF (item_code = 'HDL-C',item_value,NULL)) '高密度脂蛋白胆固醇',grouP_concat(IF (item_code = 'HDL-C',item_flag,NULL)) '高密结论',grouP_concat(IF (item_code = 'HDL-C',item_limit,NULL)) '高密范围',sum(IF (item_code = 'GLU',item_value,NULL)) '空腹血糖',grouP_concat(IF (item_code = 'GLU',item_flag,NULL)) '血糖结论',grouP_concat(IF (item_code = 'GLU',item_limit,NULL)) '血糖范围'FROMmh_jy_resultWHEREjy_parid IN (SELECTjy_paridFROMmh_jy_parsonWHEREorg_id LIKE concat(@org_id, '%'))GROUP BYjy_parid
) AS sh ON sh.jy_parid = sp.jy_parid
LEFT JOIN mh_jy_xqparson xp ON xp.tjid = j.id
LEFT JOIN (SELECTxq_parid,sum(IF (item_code = 'WBC',item_value,NULL)) '白细胞',grouP_concat(IF (item_code = 'WBC',item_flag,NULL)) '白细胞结论',grouP_concat(IF (item_code = 'WBC',item_limit,NULL)) '白细胞范围',sum(IF (item_code = 'RBC',item_value,NULL)) '红细胞',grouP_concat(IF (item_code = 'RBC',item_flag,NULL)) '红细胞结论',grouP_concat(IF (item_code = 'RBC',item_limit,NULL)) '红细胞范围',sum(IF (item_code = 'HGB',item_value,NULL)) '血红蛋白',grouP_concat(IF (item_code = 'HGB',item_flag,NULL)) '血红蛋白结论',grouP_concat(IF (item_code = 'HGB',item_limit,NULL)) '血红蛋白范围',sum(IF (item_code = 'PLT',item_value,NULL)) '血小板',grouP_concat(IF (item_code = 'PLT',item_flag,NULL)) '血小板结论',grouP_concat(IF (item_code = 'PLT',item_limit,NULL)) '血小板范围',sum(IF (item_code = 'LYMPH#',item_value,NULL)) '淋巴细胞数',grouP_concat(IF (item_code = 'LYMPH#',item_flag,NULL)) '淋巴数结论',grouP_concat(IF (item_code = 'LYMPH#',item_limit,NULL)) '淋巴数范围',sum(IF (item_code = 'LYMPH%',item_value,NULL)) '淋巴百分比',grouP_concat(IF (item_code = 'LYMPH%',item_flag,NULL)) '淋巴百分比结论',grouP_concat(IF (item_code = 'LYMPH%',item_limit,NULL)) '淋巴百分比范围',sum(IF (item_code = 'MONO#',item_value,NULL)) '单核数',grouP_concat(IF (item_code = 'MONO#',item_flag,NULL)) '单核数结论',grouP_concat(IF (item_code = 'MONO#',item_limit,NULL)) '单核数范围',sum(IF (item_code = 'MONO%',item_value,NULL)) '单核百分比',grouP_concat(IF (item_code = 'MONO%',item_flag,NULL)) '单核百分比结论',grouP_concat(IF (item_code = 'MONO%',item_limit,NULL)) '单核百分比范围',sum(IF (item_code = 'NEUT#',item_value,NULL)) '中性数',grouP_concat(IF (item_code = 'NEUT#',item_flag,NULL)) '中性数结论',grouP_concat(IF (item_code = 'NEUT#',item_limit,NULL)) '中性数范围',sum(IF (item_code = 'NEUT%',item_value,NULL)) '中性百分比',grouP_concat(IF (item_code = 'NEUT%',item_flag,NULL)) '中性百分比结论',grouP_concat(IF (item_code = 'NEUT%',item_limit,NULL)) '中性百分比范围',sum(IF (item_code = 'EOS#',item_value,NULL)) '嗜酸数',grouP_concat(IF (item_code = 'EOS#',item_flag,NULL)) '嗜酸数结论',grouP_concat(IF (item_code = 'EOS#',item_limit,NULL)) '嗜酸数范围',sum(IF (item_code = 'EO%',item_value,NULL)) '嗜酸百分比',grouP_concat(IF (item_code = 'EO%',item_flag,NULL)) '嗜酸比率结论',grouP_concat(IF (item_code = 'EO%',item_limit,NULL)) '嗜酸比范围',sum(IF (item_code = 'BASO#',item_value,NULL)) '嗜碱数',grouP_concat(IF (item_code = 'BASO#',item_flag,NULL)) '嗜碱数结论',grouP_concat(IF (item_code = 'BASO#',item_limit,NULL)) '嗜碱数范围',sum(IF (item_code = 'BASO%',item_value,NULL)) '嗜碱比',grouP_concat(IF (item_code = 'BASO%',item_flag,NULL)) '嗜碱比结论',grouP_concat(IF (item_code = 'BASO%',item_limit,NULL)) '嗜碱比范围',sum(IF (item_code = 'HCT',item_value,NULL)) '红细胞压积',grouP_concat(IF (item_code = 'HCT',item_flag,NULL)) '红压积结论',grouP_concat(IF (item_code = 'HCT',item_limit,NULL)) '红压积范围',sum(IF (item_code = 'MCHC',item_value,NULL)) '平均红细胞血红蛋白浓度',grouP_concat(IF (item_code = 'MCHC',item_flag,NULL)) '平均红白浓度结论',grouP_concat(IF (item_code = 'MCHC',item_limit,NULL)) '平均红白浓度范围',sum(IF (item_code = 'MCV',item_value,NULL)) '平均红细胞体积',grouP_concat(IF (item_code = 'MCV',item_flag,NULL)) '平均红体积结论',grouP_concat(IF (item_code = 'MCV',item_limit,NULL)) '平均红体积范围',sum(IF (item_code = 'MCH',item_value,NULL)) '平均红细胞血红蛋白含量',grouP_concat(IF (item_code = 'MCH',item_flag,NULL)) '平均红白含量结论',grouP_concat(IF (item_code = 'MCH',item_limit,NULL)) '平均红白含量范围',sum(IF (item_code = 'RDW_SD',item_value,NULL)) '红细胞分布宽度标准差',grouP_concat(IF (item_code = 'RDW_SD',item_flag,NULL)) 'r_sd结论',grouP_concat(IF (item_code = 'RDW_SD',item_limit,NULL)) 'r_sd范围',sum(IF (item_code = 'MPV',item_value,NULL)) '平均血小板体积',grouP_concat(IF (item_code = 'MPV',item_flag,NULL)) 'MPV结论',grouP_concat(IF (item_code = 'MPV',item_limit,NULL)) 'MPV范围',sum(IF (item_code = 'PCT',item_value,NULL)) '血小板压积',grouP_concat(IF (item_code = 'PCT',item_flag,NULL)) 'PCT结论',grouP_concat(IF (item_code = 'PCT',item_limit,NULL)) 'PCT范围',sum(IF (item_code = 'RDW_CV',item_value,NULL)) '红细胞分布宽度CV',grouP_concat(IF (item_code = 'RDW_CV',item_flag,NULL)) 'RDW_CV结论',grouP_concat(IF (item_code = 'RDW_CV',item_limit,NULL)) 'RDW_CV范围',sum(IF (item_code = 'PDW',item_value,NULL)) '血小板分布宽度',grouP_concat(IF (item_code = 'PDW',item_flag,NULL)) 'PDW结论',grouP_concat(IF (item_code = 'PDW',item_limit,NULL)) 'PDW范围',sum(IF (item_code = 'P-LCR',item_value,NULL)) '大型血小板比率',grouP_concat(IF (item_code = 'P-LCR',item_flag,NULL)) 'P-LCR结论',grouP_concat(IF (item_code = 'P-LCR',item_limit,NULL)) 'P-LCR范围',sum(IF (item_code = 'P-LCC',item_value,NULL)) '大血小板数目',grouP_concat(IF (item_code = 'P-LCC',item_flag,NULL)) 'P-LCC结论',grouP_concat(IF (item_code = 'P-LCC',item_limit,NULL)) 'P-LCC范围',sum(IF (item_code = 'GRNC',item_value,NULL)) '粒细胞数目',grouP_concat(IF (item_code = 'GRNC',item_flag,NULL)) '粒细胞数结论',grouP_concat(IF (item_code = 'GRNC',item_limit,NULL)) '粒细胞数范围',sum(IF (item_code = 'GRNR',item_value,NULL)) '粒细胞百分比',grouP_concat(IF (item_code = 'GRNR',item_flag,NULL)) '粒细胞百分比结论',grouP_concat(IF (item_code = 'GRNR',item_limit,NULL)) '粒细胞百分比范围',sum(IF (item_code = 'MIDC',item_value,NULL)) '中间细胞数目',grouP_concat(IF (item_code = 'MIDC',item_flag,NULL)) '中间细胞数结论',grouP_concat(IF (item_code = 'MIDC',item_limit,NULL)) '中间细胞数范围',sum(IF (item_code = 'MIDR',item_value,NULL)) '中间细胞百分比',grouP_concat(IF (item_code = 'MIDR',item_flag,NULL)) '中间细胞百分比结论',grouP_concat(IF (item_code = 'MIDR',item_limit,NULL)) '中间细胞百分比范围'FROMmh_jy_xqresultWHERExq_parid IN (SELECTxq_paridFROMmh_jy_xqparsonWHEREorg_id LIKE concat(@org_id, '%'))GROUP BYxq_parid
) AS xq ON xq.xq_parid = xp.xq_paridLEFT JOIN mh_jy_parson np ON j.id = np.tjid
AND np.jytype = 5
LEFT JOIN (SELECTjy_parid,grouP_concat(IF (item_code = 'KET',item_value,NULL)) '尿酮体',grouP_concat(IF (item_code = 'BLD',item_value,NULL)) '尿潜血',grouP_concat(IF (item_code = 'PRO',item_value,NULL)) '尿蛋白',grouP_concat(IF (item_code = 'GLU_N',item_value,NULL)) '尿糖',grouP_concat(IF (item_code = 'BIL',item_value,NULL)) '尿胆红素',grouP_concat(IF (item_code = 'LEU',item_value,NULL)) '尿白细胞',grouP_concat(IF (item_code = 'NIT',item_value,NULL)) '亚硝酸盐',grouP_concat(IF (item_code = 'URO',item_value,NULL)) '尿胆原',grouP_concat(IF (item_code = 'VC',item_value,NULL)) '抗坏血酸',grouP_concat(IF (item_code = 'PH',item_value,NULL)) 'PH',grouP_concat(IF (item_code = 'SG',item_value,NULL)) '尿比重'FROMmh_jy_resultWHEREjy_parid IN (SELECTjy_paridFROMmh_jy_parsonWHEREorg_id LIKE concat(@org_id, '%'))GROUP BYjy_parid
) AS nj ON nj.jy_parid = np.jy_parid
LEFT JOIN (SELECTjktj_id,group_concat(m.drug_name,',',m.drug_usage_code,',',m.consumption,',',m.medicationtime,',',m.compliance SEPARATOR ';') '用药情况'FROMmh_jktj_medicine m WHERE m.jktj_id in(SELECT id from mh_jktj WHERE org_id like concat(@org_id, '%') and tjrq >=@start_time and tjrq <=@end_time)GROUP BYjktj_id
) AS yaowu ON j.id = yaowu.jktj_id
WHEREj.org_id LIKE concat(@org_id, '%')
AND j.is_fufei = 0
AND j.tjrq >=@start_time
AND j.tjrq <=@end_time
and j.xdt_flag is not null and j.bc_flag is not null
and nj.尿酮体 is not null and sh.血清肌酐 is not null and xq.白细胞 is not null
and j.lxdh is not null
#and 2021档案.up_status in('21','31')
and j.age>65
GROUP BY j.org_name
limit 5
#ORDER BY length(2021档案.jkpjyc) desc limit 30

四、2021机构进度查询

SET @start_time = 20210101;
SET @end_time = 20211231;SELECT
aa.机构号,aa.机构,aa.开始查体日期,aa.最近查体日期,aa.查体总数,aa.报告打印数量,cc.档案打印数量,bb.上传成功总数
FROM(SELECTleft(d.org_id,8) as '机构号',d.NAME AS '机构',COUNT(1) AS '查体总数',DATE(min(b.tjrq)) AS '开始查体日期',DATE(max(b.tjrq)) AS '最近查体日期',count(CASEWHEN (b.dy_detail IS NOT NULL or b.zjdysj is not null) THEN'1'END) AS '报告打印数量'FROMhealth_info2021.mh_lnr_jktj b JOIN health_record2021.organization d ON LEFT (b.org_id, 8) = d.org_idWHERE  b.org_id regexp '50011301|50011110|37021406|37110212|37052105|37232810|37110104|37110103|37112106|37112103|37110208|37050201|37022105|61052401|51018601'
and b.tjrq BETWEEN @start_timeAND @end_timeAND b.is_fufei = 0GROUP BYLEFT (b.org_id, 8) ) AS aaLEFT JOIN (SELECT
left(d.org_id,8) as '机构号',d.NAME AS '机构',count(*) '档案打印数量'FROMhealth_record2021.mh_lnr_jkda a#RIGHT JOIN health_info2021.mh_jktj b ON a.mh_card = b.mh_cardleft JOIN health_record2021.mh_jkda_state c ON a.id = c.idJOIN health_record2021.organization d ON LEFT (a.org_id, 8) = d.org_idWHEREa.tjrq BETWEEN @start_timeAND @end_timeAND a.is_fufei = 0AND c.dy_detail IS NOT NULLGROUP BYLEFT (a.org_id, 8)
) AS cc ON aa.机构 = cc.机构LEFT JOIN (SELECT
left(d.org_id,8) as '机构号',d.NAME AS '机构',count(1) '上传成功总数'FROMhealth_record2021.mh_lnr_jkda aleft JOIN health_info2021.mh_jktj b ON a.mh_card = b.mh_cardJOIN health_record2021.organization d ON LEFT (b.org_id, 8) = d.org_idWHEREb.tjrq BETWEEN @start_timeAND @end_timeAND (a.up_status IN ('21', '31') or  a.zl_up_status in ('21', '31'))AND a.is_fufei = 0GROUP BYLEFT (b.org_id, 8)
) AS bb ON aa.机构 = bb.机构
;

总结:此文章仅做为记录使用。

2021数据库MYSQL语句梳理(Navicat)相关推荐

  1. pd 生成mysql语句_PDMan + Navicat Premium + MySQL 数据库设计和工具

    Navicat Premium 和 MySQL查看以前的一些文章 PDMan 简介 PDMan是一款数据库建模工具,国产开源易用.支持常用的MySQL.Oracal等数据库,具体信息查看官网:http ...

  2. mysql删除当前行 快捷_数据库-Mysql操作之Navicat快捷键操作

    一.Navicat使用技巧(附快捷键) 1.有时按快捷键Ctrl+F搜某条数据的时候搜不到,但是能用sql查出来,这是怎么回事? Ctrl+F只能搜本页数据,不在本页的数据搜不到,navicat每页默 ...

  3. mysql数据去重语句_数据库 mysql 语句

    LAMP: Linux系统 A阿帕奇服务器 Mysql数据库 Php语言 mysql:常用代码 create table CeShi1 ( Uid varchar(50) primary key, P ...

  4. mysql数据对比同步_跨数据库mysql语句同步数据和对比运算

    首先,A数据库[需要同步的数据库]A_product数据表[产品基本信息]product_id产品唯一IDprice产品价格A_product_option_value数据表[产品选项]product ...

  5. 学生选课数据库MySQL语句练习题45道

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. select Sname,Ssex,Class from Student; 2. 查询教师所有的单位即不重复的Depart ...

  6. mysql语句数据库_数据库的Mysql语句

    数据库的mysql语句: 1.连接数据库 mysql -u root -p 2.显示数据库 show databases(db); 3.选择数据库 use 数据库名; 4.显示数据库中的表 show ...

  7. MySQL之数据库基本操作语句

    ------·今天距2020年48天·------ 这是ITester软件测试小栈第78次推文 创建数据库 #创建数据库ITester create database ITester; 显示数据库列表 ...

  8. MySQL数据库体系 全面梳理(漂亮简洁的思维导图)

    MySQL数据库体系 基础 索引 锁 SQL优化 数据库优化 结语 一个平平无奇又漂亮又简洁的 MySQL数据库体系 全面梳理 思维导图罢了. 基础 基础图主要囊括了 数据库基础知识 .数据类型.存储 ...

  9. macOS安装MySQL,使用Navicat连接MySQL数据库/2022

    macOS安装MySQL,使用Navicat连接MySQL数据库/2022 intel chip 下载安装文件 进入官网 MySQL :: MySQL Downloads 选择页尾MySQL Comm ...

  10. linux服务器安装mysql数据库并通过本地Navicat连接访问远程mysq数据库

    之前因为项目需要,所以自己在linux服务器上安装了mysql数据库,但是自己在安装mysql数据库的时候也是遇到了很多的问题,所以特此在本博客中介绍一下如何在linux服务器上进行mysql数据库的 ...

最新文章

  1. mysql 关联 update_关于SQL UPDATE关联更新
  2. C语言经典例40-逆置数组
  3. java中完成md5加密解密_java实现md5加密解密 notNET中加密和解密的实现方法
  4. MySQL高级 - 索引的使用 - 覆盖索引
  5. 使用@OrderBy对Spring Data MongoDB集合进行排序
  6. C#编写TensorFlow人工智能应用 TensorFlowSharp
  7. linux-路径的切换-文件的增删拷-目录的增删拷
  8. 不占内存的浏览器_4款黑科技办公网站,高效实用,不占内存,高手的必备神器...
  9. TwinCAT软件部分参数介绍
  10. 软件测试做简历专业技能这样写,还怕没面试机会?
  11. 通过域名访问文件共享服务器,域名访问共享文件夹
  12. 学好数据结构的重要性
  13. 计算机最最最底层的工作原理是怎么运行的
  14. NLP机器翻译任务中,如何用Bleu score评价翻译质量(学习心得)
  15. Android 启动后台运行程序(Service)
  16. Android资料集合
  17. Ubuntu 无法连接上 cn.archive.ubuntu.com:80
  18. Memcached 与 Wowza 项目的集成
  19. 研究生新生的科研指南
  20. chrome设置微信ua_用Chrome在电脑上模拟微信浏览器 - 雪山玉龙 - 博客园

热门文章

  1. Visual Prompt Tuning (VPT)
  2. 详解后端工程师必看学习路线图(含初、中、高阶)
  3. 腾讯云函数要收费了,试试阿里云的云效codeup吧,这里有教程
  4. 解决:vue组件顶部留有空白问题
  5. Druid 技术白皮书:大数据实时统计分析数据存储
  6. java 指纹比对 算法_Java通过sourceafis比对指纹图片的相似度判断指纹
  7. 环信php修改头像,环信客服 如何正确设置用户的头像和昵称?
  8. MPI_Bcast函数的用法
  9. 学习LSL:Locate-Globally-Segment-locally
  10. JS复习笔记之造new轮子