select a.日完成,(select sum(a.日完成) from a where a.date >= '2009-7-1' and a.date <= '2009-7-23' ) as 月累计from a
where a.date = '2009-7-23'问下,日期23号这天没有记录,那么我想显示如下结果,需要怎样更改代码日完成  月累计
  0       78

解决方案 »

  1.   


    select isnull(a.日完成,0), 
    (select sum(a.日完成) from a where a.date >= '2009-7-1' and a.date <= '2009-7-23' ) as 月累计 
    from a 
    where a.date = '2009-7-23' 
      

  2.   


    select isnull(a.日完成,0), b.Total
     as 月累计 
    from a right join
    (select sum(a.日完成) as Total from a where a.date >= '2009-7-1' and a.date <= '2009-7-23' ) b
    where a.date = '2009-7-23' 
      

  3.   


    select isnull(a.日完成,0), b.Total
     as 月累计 
    from a right join
    (select sum(a.日完成) as Total from a where a.date >= '2009-7-1' and a.date <= '2009-7-23' ) b
    where a.date = '2009-7-23'