如:
use database_name
select csign,ino_id,
收入=sum(mc) from table_name1 where ccode like '5101%' and  dbill_date>='2006-10-1',
 税金=sum(mc) from table_name1 where ccode = '21710105',
group by csign,ino_id 
order by csign,ino_id
象上面这样不行,那怎样做简单呢?
望高手给予指点.谢谢!

解决方案 »

  1.   

    select 
        csign,ino_id,
        收入=sum(case when ccode like '5101%' and dbill_date>='2006-10-1' then mc else 0 end),
        税金=sum(case when ccode = '21710105' then mc else 0 end)
    from 
        table_name1
    group by 
        csign,ino_id 
    order by 
        csign,ino_id
      

  2.   

    试试这个:
    select csign,ino_id,
    收入=sum(case when ccode like '5101%' and  dbill_date>='2006-10-1' then mc else 0 end)
     税金=sum(case when ccode = '21710105' then mc else 0 end) 
    from table_name1 
    group by csign,ino_id 
    order by csign,ino_id
      

  3.   

    select csign,ino_id,
    isnull(sum(case when ccode like '5101%' and  dbill_date>='2006-10-1' then mc else 0 end),0) as 收入,
    isnull(sum(case when ccode = '21710105' then mc else 0 end),0) as 税金
    group by csign,ino_id 
    order by csign,ino_id