sql合并的问题?
时间:2011-11-14
来源:互联网
第二条语句的?用到了第一条语句的查询结果
SQL code
select wa.file_digest,wa.shot_time,wa.shot_district,wa.program_name,wa.tml_id,ter.decardnumber from watermark wa,ixterminal ter where 1=1 and wa.tml_id = ter.tml_id and wa.shot_district like '%%' and wa.shot_time > '' and wa.shot_time < '' and wa.program_name like '%%' and ter.decardnumber like '%%' select file_name,file_path,watermark_file_status from file_info where file_digest = ? and file_acceptance_status= 2 and rownum <= 1
作者: ask00000001 发布时间: 2011-11-14
select file_name,file_path,watermark_file_status from file_info where file_acceptance_status= 2 and rownum <= 1 and exists(select 1 from watermark wa,ixterminal ter where 1=1 and wa.tml_id = ter.tml_id and wa.shot_district like '%%' and wa.shot_time > '' and wa.shot_time < '' and wa.program_name like '%%' and ter.decardnumber like '%%' and wa.file_digest=file_info.file_digest)
作者: lxpbs8851 发布时间: 2011-11-14
作者: ask00000001 发布时间: 2011-11-14
SQL code
select file_name,file_path,watermark_file_status
from file_info
where file_acceptance_status= 2 and rownum <= 1
and exists(select 1 from watermark wa,ixterminal ter where 1=1
and ……
sql1中的字段保留
作者: ask00000001 发布时间: 2011-11-14
作者: ask00000001 发布时间: 2011-11-14
SQL code
select file_name,file_path,watermark_file_status
from file_info
where file_acceptance_status= 2 and rownum <= 1
and exists(select 1 from watermark wa,ixterminal ter where 1=1
and wa……
这样子的写法,达不到要求嘛?
作者: cosio 发布时间: 2011-11-14
select wa.file_digest,wa.shot_time,wa.shot_district,wa.program_name,wa.tml_id,ter.decardnumber, (select max(file_name) from file_info where file_digest=wa.file_digest and file_acceptance_status= 2) as file_name, (select max(file_path) from file_info where file_digest=wa.file_digest and file_acceptance_status= 2) as file_path, (select max(watermark_file_status) from file_info where file_digest=wa.file_digest and file_acceptance_status= 2) as watermark_file_status from watermark wa,ixterminal ter where 1=1 and wa.tml_id = ter.tml_id and wa.shot_district like '%%' and wa.shot_time > '' and wa.shot_time < '' and wa.program_name like '%%' and ter.decardnumber like '%%'
作者: lxpbs8851 发布时间: 2011-11-14
select wa.file_digest,wa.shot_time,wa.shot_district,wa.program_name,wa.tml_id,ter.decardnumber from watermark wa,ixterminal ter where 1=1 and wa.tml_id = ter.tml_id and wa.shot_district like '%%' and wa.shot_time > '' and wa.shot_time < '' and wa.program_name like '%%' and ter.decardnumber like '%%' select file_name,file_path,watermark_file_status from file_info where file_digest = ? and file_acceptance_status= 2 and rownum <= 1
第二条语句的?用到了第一条语句的查询结果
sql1中的file_digest,在sql2中都有多条记录
1对多,但是只取file_acceptance_status= 2的那条(等于2的仅有一条),或者没有
但是用空表示出来
例如
sql1中有100条不同的
file_digest,file_info
中也必须有100条
没有符合file_acceptance_status= 2的也显示出来(null)
作者: ask00000001 发布时间: 2011-11-14
作者: ask00000001 发布时间: 2011-11-14
那就不要用EXISTS要,用(+)
作者: cosio 发布时间: 2011-11-14
select wa.file_digest, wa.shot_time, wa.shot_district, wa.program_name, wa.tml_id, ter.decardnumber, finfo.file_name, finfo.file_path, finfo.watermark_file_status from watermark wa, ixterminal ter, (select file_digest,file_name,file_path,watermark_file_status from file_info where file_acceptance_status= 2 and rownum <= 1) finfo where 1=1 and wa.tml_id = ter.tml_id and wa.shot_district like '%%' and wa.shot_time > '' and wa.shot_time < '' and wa.program_name like '%%' and ter.decardnumber like '%%' and wa.file_digest = finfo.file_digest(+);
作者: xiaobn_cn 发布时间: 2011-11-14
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28