日期:2014-05-18  浏览次数:20588 次

一个select查询多表的问题。
一个select查询多表的问题,
当前查询的结果有一个问题,就是当“f.Fdate 订单日期”这个字段是空值的时候,查询的结果集显示记录,我该怎么样改写这条查询语句,当“f.Fdate 订单日期”这个字段是空值的时候也显示查询的记录?不知道这样讲大家能不能听明白:(

SQL语句如下:
select distinct d.fnumber 供应商代码,c.fnumber 物料代码,e.fname 单位,b.fprice 不含税单价,d.fname 供应商名称,c.fname 物料名称,a.Fdate 入库日期,f.Fdate 订单日期
from icstockbill a,icstockbillentry b,t_icitem c,t_supplier d,t_MeasureUnit e,poorder f

where c.funitid=e.fmeasureunitid and a.finterid=b.finterid and d.fitemid=a.fsupplyid and a.ftrantype=1 and d.fnumber=0038 and d.fitemid=a.fsupplyid and a.fsupplyid=f.fsupplyid

------解决方案--------------------
试试外连接
------解决方案--------------------
最好能给出测试数据和所需要的结果

你可以去试试 FULL JOIN
------解决方案--------------------
select distinct d.fnumber 供应商代码,c.fnumber 物料代码,e.fname 单位,b.fprice 不含税单价,d.fname 供应商名称,c.fname 物料名称,a.Fdate 入库日期,f.Fdate 订单日期
from icstockbill a,icstockbillentry b,t_icitem c,t_supplier d,t_MeasureUnit e,poorder f
where c.funitid=e.fmeasureunitid and a.finterid=b.finterid and d.fitemid=a.fsupplyid and a.ftrantype=1 and d.fnumber=0038 and d.fitemid=a.fsupplyid and a.fsupplyid=f.fsupplyid


distinct 处理的吧。LZ试试看去掉distinct 有 订单日期是null值得没?

------解决方案--------------------
跟distinct没关系,f.Fdate =null就关联不到相关表的数据了。
------解决方案--------------------
在對應條件加上
OR f.Fdate IS nulll