Select 标志,(case when 收付 = 1 then 金额 else 0 end) as 收金额,
(case when 收付 = 0 then 金额 else 0 end) as 付金额
from 表

解决方案 »

  1.   

    select 标志
      ,收金额=case 收付 when 1 then 金额 else 0 end
      ,付金额=case 收付 when 0 then 金额 else 0 end
    from 表 order by 标志
      

  2.   

    或:
    Select 标志,收付 * 金额 as 收金额,(1-收付)* 金额  as 付金额 from 表-- 金额*1 = 金额   1-1 = 0 1-0 = 1
      

  3.   

    或:
    Select 标志,收付 * 金额 as 收金额,(1-收付)* 金额  as 付金额 from 表
    order by 标志
    -- 金额*1 = 金额  金额*0 = 0  1-1 = 0 1-0 = 1
      

  4.   

    select 标志,sum(case when 收付  =1 then 金额 else 0) as 收金额  ,sum(case when 收付  =0 then 金额 else 0) as 付金额  from a group by 标志
      

  5.   

    写错了
    select 标志,(case when 收付  =1 then 金额 else 0 end) as 收金额  ,(case when 收付  =0 then 金额 else 0 end ) as 付金额  from a