本帖最后由 fanlyfly_yang1 于 2010-07-23 22:10:27 编辑

解决方案 »

  1.   

    left join下select a.*,b.his_price1,b.his_price2,b.his_price3,b.his_price4
    from flowers_sale a
    left join flower_sale_his b on a.flower_id=b.flower_id
    where a.flower_id=输入值
    ;
      

  2.   

    最好还是分开写吧,没必要查一个表记录时做表连接啊
    第三种情况表连接条件是flower_id, date, price1, price2, price3四个字段都要的吧,并且还是全连接
      

  3.   

    查一个表的时候肯定是没问题,问题是多个表的时候,以那个表为基准,union不行因为不是相同的列,left join也不行,因为哪个表有数据是不确定的
      

  4.   

    left join的话,下面的第三条记录就不会出来
    276773 2010-01-03 null null null 567 null 890 123
      

  5.   

    用完全外连接啊,好象应该是ID和日期两个字段?select NVL(a.flower_id,b.flower_id) flower_id,NVL(a.date,b.date) date
           ,a.price1,a.price2,a.price3,b.his_price1,b.his_price2,b.his_price3,b.his_price4
    from flowers_sale a full outer join flower_sale_his b
           on a.flower_id=b.flower_id and a.date=b.date
    order by 1,2