mimic数据库提取(Navicat)

文章介绍了SQL查询中的多种技巧,包括使用正则表达式进行模糊匹配,处理多个查询条件,给表和字段取别名以提高可读性,以及如何连接多个表和筛选重复数据。示例涉及了LIKE运算符、LEFTJOIN和DISTINCT关键字的应用。
摘要由CSDN通过智能技术生成

1、根据英文查询对应编码,~* 可以忽略字符串长度进行匹配

select icd9_code,long_title from mimiciii.d_icd_diagnoses where long_title ~* 'myocardial'

 也可以用LIKE

//long_title中以Tub开头的数据
select * from mimiciii.d_icd_diagnoses where long_title like 'Tub%'  
//long_title中含有pne的数据
select * from mimiciii.d_icd_diagnoses where long_title like '%pne%'
//long_title中第二个位置和第三个位置是ul的数据
select * from mimiciii.d_icd_diagnoses where long_title like '_ul%'
//long_title中以P开头的字符长度大于3的数据
select * from mimiciii.d_icd_diagnoses where long_title like 'P_%_%'
//long_title中以A结尾的数据
select * from mimiciii.d_icd_diagnoses where long_title like '%A'
//long_title中a在第二个位置上且以A结尾的数据
select * from mimiciii.d_icd_diagnoses where long_title like '_a%A'
//long_title中以B开头,以s结尾且长度是10的数据
select * from mimiciii.d_icd_diagnoses where long_title like 'B________s'

 2、查询条件有多个

同一列数据有多个限制条件:

select * from mimiciii.diagnoses_icd where icd9_code in('486','40301','7100')

 不同列数据有多个限制条件(且):

select * from mimiciii.admissions where subject_id = '22' and hadm_id = '165315'

 3、给表和字段取别名,增强可读性

select subject_id,dob as death_time from mimiciii.patients  //as也可以省略

 4、连接多个表

mimic一般只会用到左连,将患者的诊断信息表与其他表相连

left join 会返回左表所有内容以及根据左表筛选出来的右表的内容

select t1.subject_id,t1.hadm_id,t1.icd9_code,t2.gender,t2.death_time
from mimiciii.diagnoses_icd as t1
left join mimiciii.patients as t2
on t1.subject_id = t2.subject_id
where t1.icd9_code in('486','40301','7100')

5、筛选再筛选,根据icd9_code合并两个表得到得某种病患者的subject_id,hadm_id

WITH d_icd_diagnoses_view AS ( 
	SELECT icd9_code, long_title 
	FROM d_icd_diagnoses 
	WHERE long_title ~* 'Acute myocardial infarction' 
)
SELECT t1.subject_id,t1.hadm_id,t1.icd9_code,t2.long_title 
FROM diagnoses_icd AS t1
INNER JOIN d_icd_diagnoses_view AS t2 
ON t1.icd9_code = t2.icd9_code 
GROUP BY t1.subject_id,t1.hadm_id,t1.icd9_code,t2.long_title

6、删除重复的数据

select DISTINCT label from label_view

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值