日期:2014-05-17  浏览次数:20799 次

SQL查询语句
现有个查询语句, 主要关联产品表,由日期检索出产品的生产和销售数量。如下:
产品表  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 就行。)

------解决方案--------------------
那就把产品表当主表  依次左连接生产情况表和销售情况表