自学数据库之一个自己写的SQL语句
2015-06-17 21:33
323 查看
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 申请医生
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 申请医生
相关文章推荐
- Oracle 连接字符串
- 2015061702 - mysql从一个表中的数据插入到另一张表中
- PB 调用存储过程[Oracle]
- Oracle分页模板
- SP_who2分析数据库性能
- 转载:用Kafka实时复制PostgreSQL里的最新数据
- Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'XXX' in 'whe
- sql server获取当前日期
- mysql添加用户和入门命令
- oracle11g字符集问题之一
- SQL中为什么引出begin...end???
- Redis数据类型之string类型
- SQL中的循环
- SQL中的循环:while 1
- sqlplus将查询结果重定向到文件,不输出到屏幕
- 为什么要用数据库?
- Sqlite数据库锁死问题
- hive中sql解析出对应表和字段的调查
- MySQL绿色版的安装(mysql-5.6.22-win32.zip)
- SQL中如何才能将查询的结果数据存在一个变量中???