自学数据库之一个自己写的SQL语句

来源:互联网 发布:c4d r17 mac破解 编辑:程序博客网 时间:2024/05/18 09:16

1,自己写的查询语句:

select   b.yq,b.ybh,
a.ksdh,
a.sjys,
a.brdh as 住院号,
b.num_result as 检验结果,
b.jyrq as 检验日期,
a.brxm as 病人姓名,
(case a.brxb when '1' then '男' when '2' then '女' when 'F' then '女' when 'M' then '男' else '其他' end ) as 病人性别,
a.nl as 年龄,
(case a.nldw when '1' then '岁' when '2' then '月' when '3' then '天' when '4' then '时' else '其他' end ) as 年龄单位,
a.zd as 临床诊断,
(select zdmc from com_dict c where a.ksdh=c.zddh and zdlb='DP') as '科室/病区',
(select zdmc from com_dict c where a.sjys=c.zddh) as 申请医生
from lis_result b ,lis_pat a
where b.yq = a.yq and b.ybh=a.ybh and b.jyrq=a.jyrq
 and b.jyrq>='2015-04-01' and b.jyrq<='2015-06-14' and  b.xmdh='PLT' and b.num_result <75 order by b.jyrq

2,分析:

case。。。when.....then......when......then......else.........end

(select zdmc from com_dict c where a.ksdh=c.zddh and zdlb='DP') as '科室/病区', z注:加zdlb='DP'是为了解决返回多个值的问题
(select zdmc from com_dict c where a.sjys=c.zddh) as 申请医生

0 0
原创粉丝点击