ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: wuxiang_123

[原创] 透视表基础你懂得有几多

  [复制链接]

TA的精华主题

TA的得分主题

发表于 2011-3-21 15:26 | 显示全部楼层
这个要好好学习一下 谢谢楼主精彩讲解!

TA的精华主题

TA的得分主题

发表于 2011-3-21 23:23 | 显示全部楼层
原帖由 wanghaiqn1957 于 2011-3-21 10:21 发表

我也是,要什么级别才能做到这一点


传说是高级

TA的精华主题

TA的得分主题

发表于 2011-3-22 07:45 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-3-22 12:22 | 显示全部楼层
参考:
  1. select 产品,月份,
  2. (select last(数量) from
  3. (select month(日期) as 月份,产品,last(数量) as 数量 from [Sheet1$a:c]where 数量 is not null group by month(日期),产品)a
  4. where a.月份<=a1.月份 and a.产品=a1.产品 group by 产品) as 数量
  5. from
  6. (select DISTINCT a.产品,month(b.日期) as 月份 from [Sheet1$a:c]a,[Sheet1$a:c]b where a.产品 is not null and b.日期 is not null)a1
  7. union all
  8. select a3.产品,"合计",a3.数量 from
  9. (
  10. select 产品,月份,
  11. (select last(数量) from
  12. (select month(日期) as 月份,产品,last(数量) as 数量 from [Sheet1$a:c]where 数量 is not null group by month(日期),产品)a
  13. where a.月份<=a1.月份 and a.产品=a1.产品 group by 产品) as 数量
  14. from
  15. (select DISTINCT a.产品,month(b.日期) as 月份 from [Sheet1$a:c]a,[Sheet1$a:c]b where a.产品 is not null and b.日期 is not null)a1
  16. )a3,
  17. (select max(month(日期)) as 月份 from [Sheet1$a:c]where 日期 is not null)b3
  18. where a3.月份=b3.月份
复制代码

增加一个用纯SQL完成的.
  1. TRANSFORM first(数量)
  2. select 产品 from
  3. (select 产品,月份,last(数量) as 数量 from
  4. (select a1.产品,a1.月份,数量 from
  5. (select a.产品,month(b.日期) as 月份 from [Sheet1$]a,[Sheet1$]b where a.产品 is not null and b.日期 is not null)a1,
  6. (select month(日期) as 月份,产品,last(数量) as 数量 from [Sheet1$]where 数量 is not null group by month(日期),产品)b1
  7. where a1.月份>=b1.月份 and a1.产品=b1.产品)
  8. group by 产品,月份
  9. union all
  10. select 产品,"合计",last(数量) as 数量 from
  11. (select a1.产品,a1.月份,数量 from
  12. (select a.产品,month(b.日期) as 月份 from [Sheet1$]a,[Sheet1$]b where a.产品 is not null and b.日期 is not null)a1,
  13. (select month(日期) as 月份,产品,last(数量) as 数量 from [Sheet1$]where 数量 is not null group by month(日期),产品)b1
  14. where a1.月份>=b1.月份 and a1.产品=b1.产品)
  15. group by 产品,"合计")
  16. group by 产品
  17. PIVOT 月份
复制代码

PS:为方便测试不同情况下是否通用,更改了数据源的数据.

[ 本帖最后由 wuxiang_123 于 2011-3-23 11:42 编辑 ]
参考.png

如何透视.rar

6.22 KB, 下载次数: 46

TA的精华主题

TA的得分主题

发表于 2011-3-22 13:09 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
原帖由 wuxiang_123 于 2011-3-22 12:22 发表
参考:select 产品,月份,
(select last(数量) from
(select month(日期) as 月份,产品,last(数量) as 数量 from [Sheet1$a:c]where 数量 is not null group by month(日期),产品)a
where a.月份


非常感谢!

TA的精华主题

TA的得分主题

发表于 2011-3-22 22:01 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2011-3-24 22:24 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2011-3-25 00:01 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2011-3-28 20:45 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2011-3-28 22:51 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-28 12:44 , Processed in 0.046186 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表