|
本帖最后由 Danger326 于 2013-2-2 14:55 编辑
因分析数据需要,经常要使用累计数,所以想到用select方式透视数据,语句中用UNION ALL把每个累计月的记录加在一起。
如:
select 公司,年度,月度,地区,销售流水 from `单店数据库$` union all
select 公司,年度,'累计1月',地区,销售流水 from `单店数据库$` where 月度=1 union all
select 公司,年度,'累计2月',地区,销售流水 from `单店数据库$` where 月度<=2 union all
select 公司,年度,'累计3月',地区,销售流水 from `单店数据库$` where 月度<=3 union all
select 公司,年度,'累计4月',地区,销售流水 from `单店数据库$` where 月度<=4 union all
select 公司,年度,'累计5月',地区,销售流水 from `单店数据库$` where 月度<=5 union all
select 公司,年度,'累计6月',地区,销售流水 from `单店数据库$` where 月度<=6 union all
select 公司,年度,'累计7月',地区,销售流水 from `单店数据库$` where 月度<=7 union all
select 公司,年度,'累计8月',地区,销售流水 from `单店数据库$` where 月度<=8 union all
select 公司,年度,'累计9月',地区,销售流水 from `单店数据库$` where 月度<=9 union all
select 公司,年度,'累计10月',地区,销售流水 from `单店数据库$` where 月度<=10 union all
select 公司,年度,'累计11月',地区,销售流水 from `单店数据库$` where 月度<=11 union all
select 公司,年度,'累计12月',地区,销售流水 from `单店数据库$` where 月度<=12
但是发现一个问题,当SELECT的数据源字段多于85列且合并2个以上表的时候,就会提示“定义了过多字段”,不会是数据源有乱码或空白字段的原因,已经检查过。
附件有3个表取数测试:
1、字段有97列,只合并1月,可以正常取数;
2、字段有86列,合并1月和2月,不能正常取数;
3、字段有85列,合并1月-12月,可以正常取数。
难道EXCEL里的SELECT有数据限制,还是我的操作不正确,求高手解答。
外部数据透视.rar
(30.3 KB, 下载次数: 20)
注:附件在放在E:\根目录下,否则会提示路径错误(顺便请教下:有没有办法解决这个路径问题,使文件放在任何路径下都可以正常取数)
|
|