先做一个类似表17的透视,近5万条数据,WinXP+Excel2007+双核(3G)+1G内存时测试,3分钟完成。因文件过大,楼主的原表及格式有些已经删除。只保留数据库和结果。如附件
88888.rar
(415.73 KB, 下载次数: 26)
:
- select
- "总计" as 客户名称,
- "总计" as 日期,
- "总计" as 摘要,
- (select sum(iif(isnull(应收款),0,应收款)) as 应收款 from (select 客户名称,日期,款项月份,摘要,所属场馆,sum(iif(isnull(应收帐款),0,应收帐款)) as 应收款,sum(iif(isnull(应付帐款),0,应付帐款)) as 应付款,sum(iif(isnull(已收帐款),0,已收帐款)) as 已收款,sum(iif(isnull(已付帐款),0,已付帐款)) as 已付款 from [数据库$] group by 客户名称,日期,款项月份,摘要,所属场馆)) as 应收款,
- (select sum(iif(isnull(已收款),0,已收款)) as 已收款 from (select 客户名称,日期,款项月份,摘要,所属场馆,sum(iif(isnull(应收帐款),0,应收帐款)) as 应收款,sum(iif(isnull(应付帐款),0,应付帐款)) as 应付款,sum(iif(isnull(已收帐款),0,已收帐款)) as 已收款,sum(iif(isnull(已付帐款),0,已付帐款)) as 已付款 from [数据库$] group by 客户名称,日期,款项月份,摘要,所属场馆)) as 已收款,
- (select sum(iif(isnull(应收款),0,应收款))-sum(iif(isnull(已收款),0,已收款)) as 未收款 from (select 客户名称,日期,款项月份,摘要,所属场馆,sum(iif(isnull(应收帐款),0,应收帐款)) as 应收款,sum(iif(isnull(应付帐款),0,应付帐款)) as 应付款,sum(iif(isnull(已收帐款),0,已收帐款)) as 已收款,sum(iif(isnull(已付帐款),0,已付帐款)) as 已付款 from [数据库$] group by 客户名称,日期,款项月份,摘要,所属场馆)) as 未收款
- from
- (select 客户名称,日期,款项月份,摘要,所属场馆,sum(iif(isnull(应收帐款),0,应收帐款)) as 应收款,sum(iif(isnull(应付帐款),0,应付帐款)) as 应付款,sum(iif(isnull(已收帐款),0,已收帐款)) as 已收款,sum(iif(isnull(已付帐款),0,已付帐款)) as 已付款 from [数据库$] group by 客户名称,日期,款项月份,摘要,所属场馆)
- union
- select
- a.客户名称,
- a.日期,
- a.摘要,
- a.应收款,
- a.已收款,
- (
- select
- sum(iif(isnull(应收款),0,应收款))-sum(iif(isnull(已收款),0,已收款)) as 未收款
- from
- (select 客户名称,日期,款项月份,摘要,所属场馆,sum(iif(isnull(应收帐款),0,应收帐款)) as 应收款,sum(iif(isnull(应付帐款),0,应付帐款)) as 应付款,sum(iif(isnull(已收帐款),0,已收帐款)) as 已收款,sum(iif(isnull(已付帐款),0,已付帐款)) as 已付款 from [数据库$] group by 客户名称,日期,款项月份,摘要,所属场馆)b
- where
- a.客户名称=b.客户名称
- and
- a.日期>=b.日期
- ) as 未收款
- from
- (select 客户名称,日期,款项月份,摘要,所属场馆,sum(iif(isnull(应收帐款),0,应收帐款)) as 应收款,sum(iif(isnull(应付帐款),0,应付帐款)) as 应付款,sum(iif(isnull(已收帐款),0,已收帐款)) as 已收款,sum(iif(isnull(已付帐款),0,已付帐款)) as 已付款 from [数据库$] group by 客户名称,日期,款项月份,摘要,所属场馆)a
- order by
- 客户名称 asc,
- 日期 asc
复制代码 |