现有个查询语句, 主要关联产品表,由日期检索出产品的生产和销售数量。如下:
产品表 CP (id,name)
生产情况表 SC(num,cp_id,fdate)
销售情况表 XS(num,cp_id,fdate)
i_inputDate 输入的日期。
select sc.num snum,xs.num xnum ,(xs.num/sc.num) bili
from sc,xs,cp
where sc.cp_id = cp.id and xs.cp_id = cp.id and sc.fdate =i_inputDate and xs.fdate =i_inputDate。
当生产或销售表中 某个日期上没有记录时,SQL检索的结果为空,该如何修改SQL 使得 即使某个日期上无记录时,也能检索出数据( 无记录的数据为null 就行。)
产品表 CP (id,name)
生产情况表 SC(num,cp_id,fdate)
销售情况表 XS(num,cp_id,fdate)
i_inputDate 输入的日期。
select sc.num snum,xs.num xnum ,(xs.num/sc.num) bili
from sc,xs,cp
where sc.cp_id = cp.id and xs.cp_id = cp.id and sc.fdate =i_inputDate and xs.fdate =i_inputDate。
当生产或销售表中 某个日期上没有记录时,SQL检索的结果为空,该如何修改SQL 使得 即使某个日期上无记录时,也能检索出数据( 无记录的数据为null 就行。)
解决方案 »
- CLOB、BLOB字段的表无法导入,ORA-01536: 超出表空间 'SYSTEM' 的空间限额。
- 大表一定要建立分区吗,作用什么?
- 关于简单的存储过程
- 就50分了!全给了!高手请进!
- 将oracle库中一张表的内容导出到一个txt文件后,为什么字段之间有空格?
- 如何在sqlplus中执行procedure
- sql 难题!想了半天,没有什么好主意!对一个表进行更新的操作,对相关字段相同的纪录,在一个序号字段中,显示出不同的纪录数
- INSERT 问题?
- 问个初级问题,怎么创建包?--求救呀
- ORACLE:update表的某一个字段全部后面加一个字符串
- ORACLE 卸数的图文过程
- oracle 查询的时候 关于in的问题
from sc,xs,cp
where sc.cp_id = cp.id and xs.cp_id = cp.id and (sc.fdate =i_inputDate OR sc.fdate is null) and (xs.fdate =i_inputDate OR xs.fdate is null)
from sc
left join cp
on sc.cp_id = cp.id
left join xs
on xs.cp_id = cp.id
where sc.fdate = i_inputDate
and xs.fdate = i_inputDate
把各自表中对应的月份数据检索出来。
例如生产表9月份没数据,而销售表9月份有数据,
我希望 显示结果为A , 如果都没记录我希望结果为B,不管怎样都不要no_data_found
生产数量 销售数量 比例
A null 999 null
B null null null
现在 where后面 日期比较条件不满足时 检索出来的记录为0,我希望也检索出数据用 null来代替数量
and xs.fdate = i_inputDate 条件去掉吧,,看你这需求,没啥用
and xs.fdate = i_inputDate 条件去掉吧,,看你这需求,没啥用
这条件去掉, 那不把所有日期的数据都查出来?
select b.num snum,c.num xnum,decode(b.num,null,'null',0,'null',c.num/b.num) bl from tt t,sc b, xs c
where t.months=to_char(b.fdate,'yyyymm')(+) and t.months=to_char(c.fdate,'yyyymm')(+)
and xs.fdate = i_inputDate 条件去掉吧,,看你这需求,没啥用
这条件去掉, 那不把所有日期的数据都查出来?
select sc.num snum, xs.num xnum, (xs.num / sc.num) bili
from sc
left join cp
on sc.cp_id = cp.id
left join xs
on xs.cp_id = cp.id
and xs.fdate = i_inputDate
where sc.fdate = i_inputDate
这样呢