select 
    B.intYear,
    sum(A.amount),
    sum(case A.typeID when 55 then A.amount else 0 end)
from
    A,B
where
    A.prjID = B.prjID
group by
    B.intYear

解决方案 »

  1.   

    select B.intYear,sum(A.amount),sum(case when A.typeID=55 then A.amount else 0 end) from
    A,B where A.prjID = B.prjID group by B.intYear
      

  2.   

    select intyear,sum(amoutnt) from (select a.*,b.*  
    from a left outer join b  on a.prjid=b.prjid)aa 
    group by intyear
    select intyear,sum(amoutnt) from (select a.*,b.*  
    from a left outer join b  on a.prjid=b.prjid)aa 
    where typeid=55
    group by intyear
      

  3.   

    select a.intYear,sum(b.amount )
    from 表1 a,表2 b
    where a.prjID=b.prjID and a.typeID = 55
    group by a.intYear
      

  4.   

    select a.intYear,sum(b.amount )
    from 表1 a,表2 b
    where a.prjID=b.prjID and a.typeID = 55
    group by a.intYear
    union
    select a.intYear,sum(b.amount )
    from 表1 a,表2 b
    where a.prjID=b.prjID
    group by a.intYear
      

  5.   

    借用 libin_ftsafe(子陌红尘)
    select 
        B.intYear,
        sum(A.amount),
        sum(case A.typeID when 55 then A.amount else 0 end)
    from
        A,B
    where
        A.prjID = B.prjID
    group by
        B.intYear
      

  6.   

    谢谢各位的关注!!
    我用的是SQL sever 2000 用不支持case 语句这样的用法,问一下有没有其他的办法呀??
      

  7.   

    SQL server 2000是支持case 的!