select a.日期,a.代码,a.发生额,b.占用天数 from 表1 a,表2 b where a.日期=b.日期 and a.代码=b.代码 order by a.日期

解决方案 »

  1.   

    select a.日期,a.代码,a.发生额,CASE WHEN b.占用天数 IS NULL THEN 0 ELSE b.占用天数 
    from 表1 LEFT JOIN 表2 b ON a.日期=b.日期 and a.代码=b.代码 
    order by a.日期
    我想是这样!我胆小!
      

  2.   

    select a.日期,a.代码,a.发生额,isnull(b.占用天数,0) as b.占用天数 
    from 表1 a LEFT JOIN 表2 b ON a.日期=b.日期 and a.代码=b.代码 
    order by a.日期