select custom
  ,sum(case when state=1 then total else 0 end) 应收
  ,sum(case when state=0 then total else 0 end) 欠款
from table1 group by custom

解决方案 »

  1.   

    表table1三个字段:custom(客户姓名),total(应收款),state(结算状态:true或false)
    每个custom有多条记录,有多个custom,现在要统计每个客户的应收款总额和未结算款的总额,用一个sql语句怎么写select custom as 客户姓名
      ,sum(total) as 应收款
      ,sum(case state when 1 then 0 else total) as 欠款
    from table1
    group by custom
      

  2.   

    你说你的state的值为true或false是什么意思? 
    你是ACCESS数据库吗?如果是,就用:
    select custom as 客户姓名
      ,sum(total) as 应收款
      ,sum(iif(state=false,0,total)) as 欠款
    from table1
    group by custom