select
    a.Customer as 客户,
    count(distinct a.lngSaleNo) as 票数,
    sum(case when StrYSYF='应收' and StrBZ='RMB' then b.DblAmount end) as 应收RMB,
    sum(case when StrYSYF='应收' and StrBZ='HKD' then b.DblAmount end) as 应收HKD,
    sum(case when StrYSYF='应收' and StrBZ='USD' then b.DblAmount end) as 应收USD,
    sum(case when StrYSYF='应付' and StrBZ='RMB' then b.DblAmount end) as 应付RMB,
    sum(case when StrYSYF='应付' and StrBZ='HKD' then b.DblAmount end) as 应付HKD,
    sum(case when StrYSYF='应付' and StrBZ='USD' then b.DblAmount end) as 应付USD
from
    Sale a,SaleDetail b
where
    a.LngSaleNo=b.LngSaleNo
group by
    a.Customer