ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1423|回复: 5

两天两夜了,就是找不出原因,到底错在哪来,麻烦大侠们帮帮忙。。

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-3-13 11:14 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
图片一中,我SELECT 了11天的数据,数量的计算项和单价的计算项中就能显示出来,图片二、但是如果到13天或以上就会等于零。。很是奇怪。。金额的计算项又不会。。。真搞不明白了!不就是在隔壁一列而已。。(11日里面有数据,13日里面没数据),但是我又尝试把每日的都加上数据,还是不行。。。。大侠们帮帮忙,小弟万分感谢 每日采购物料清单.rar (130.25 KB, 下载次数: 29)
图片二.jpg
图片一.jpg

TA的精华主题

TA的得分主题

发表于 2012-3-13 11:29 | 显示全部楼层
大致来看,有数量列中好像有非数值型。连接代码改成
  1. select 品名,sum(数量) as 数量,sum(金额) as 金额 from (select * FROM [1日$B3:G103] union all select * FROM [2日$B3:G103] union all select * FROM [3日$B3:G103] union all select * FROM [4日$B3:G103] union all select * FROM [5日$B3:G103] union all select * FROM [6日$B3:G103] union all select * FROM [7日$B3:G103] union all select * FROM [8日$B3:G103] union all select * FROM [9日$B3:G103] union all select * FROM [10日$B3:G103] union all select * FROM [11日$B3:G103] union all select * FROM [12日$B3:G103] union all select * FROM [13日$B3:G103] union all select * FROM [14日$B3:G103] union all select * FROM [15日$B3:G103] union all select * FROM [16日$B3:G103] union all select * FROM [17日$B3:G103] union all select * FROM [18日$B3:G103] union all select * FROM [19日$B3:G103] union all select * FROM [20日$B3:G103] union all select * FROM [21日$B3:G103] union all select * FROM [22日$B3:G103] union all select * FROM [23日$B3:G103] union all select * FROM [24日$B3:G103] union all select * FROM [25日$B3:G103] union all select * FROM [26日$B3:G103] union all select * FROM [27日$B3:G103] union all select * FROM [28日$B3:G103] union all select * FROM [29日$B3:G103] union all select * FROM [30日$B3:G103] union all select * FROM [31日$B3:G103]) group by 品名
复制代码
好像就可以了

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-3-13 11:39 | 显示全部楼层
本帖最后由 卖猪仔二号 于 2012-3-13 11:39 编辑

那如果要加上分类呢?group by 品名是什么意思?

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-3-13 11:48 | 显示全部楼层
本帖最后由 卖猪仔二号 于 2012-3-13 11:49 编辑

我想能按分类、品名、“1日” as 日期,数量加起来,单价平均求平均值。怎么做到你呢?麻烦你啦。


select 分类,品名,数量,单价,"1日" as 日期 FROM [1日$B3:G103] union all select 分类,品名,数量,单价,"2日" as 日期 FROM [2日$B3:G103] union all select 分类,品名,数量,单价,"3日" as 日期 FROM [3日$B3:G103] union  all  select 分类,品名,数量,单价,"4日" as 日期 FROM [4日$B3:G103] union all  select 分类,品名,数量,单价,"5日" as 日期 FROM [5日$B3:G103] union all select 分类,品名,数量,单价,"6日" as 日期 FROM [6日$B3:G103] union all select 分类,品名,数量,单价,"7日" as 日期 FROM [7日$B3:G103] union all select 分类,品名,数量,单价,"8日" as 日期 FROM [8日$B3:G103] union all select 分类,品名,数量,单价,"9日" as 日期 FROM [9日$B3:G103] union all select 分类,品名,数量,单价,"10日" as 日期 FROM [10日$B3:G103] union all select 分类,品名,数量,单价,"11日" as 日期 FROM [11日$B3:G103] union all select 分类,品名,数量,单价,"12日" as 日期 FROM [12日$B3:G103] union all select 分类,品名,数量,单价,"13日" as 日期 FROM [13日$B3:G103] union all select 分类,品名,数量,单价,"14日" as 日期 FROM [14日$B3:G103] union all select 分类,品名,数量,单价,"15日" as 日期 FROM [15日$B3:G103] union all select 分类,品名,数量,单价,"16日" as 日期 FROM [16日$B3:G103] union all select 分类,品名,数量,单价,"17日" as 日期 FROM [17日$B3:G103] union all select 分类,品名,数量,单价,"18日" as 日期 FROM [18日$B3:G103] union all select 分类,品名,数量,单价,"19日" as 日期 FROM [19日$B3:G103] union all select 分类,品名,数量,单价,"20日" as 日期 FROM [20日$B3:G103] union all select 分类,品名,数量,单价,"21日" as 日期 FROM [21日$B3:G103] union all select 分类,品名,数量,单价,"22日" as 日期 FROM [22日$B3:G103] union all select 分类,品名,数量,单价,"23日" as 日期 FROM [23日$B3:G103] union all select 分类,品名,数量,单价,"24日" as 日期 FROM [24日$B3:G103] union all select 分类,品名,数量,单价,"25日" as 日期 FROM [25日$B3:G103] union all select 分类,品名,数量,单价,"26日" as 日期 FROM [26日$B3:G103] union all select 分类,品名,数量,单价,"27日" as 日期 FROM [27日$B3:G103] union all select 分类,品名,数量,单价,"28日" as 日期 FROM [28日$B3:G103] union all select 分类,品名,数量,单价,"29日" as 日期 FROM [29日$B3:G103] union all select 分类,品名,数量,单价,"30日" as 日期 FROM [30日$B3:G103] union all select 分类,品名,数量,单价,"31日" as 日期 FROM [31日$B3:G103]


这是我之前写的

TA的精华主题

TA的得分主题

发表于 2012-3-13 12:04 | 显示全部楼层
本帖最后由 zm0115 于 2012-3-13 12:05 编辑
卖猪仔二号 发表于 2012-3-13 11:39
那如果要加上分类呢?group by 品名是什么意思?

select 品名,分类,sum(数量) as 数量,avg(单价) as 单价,sum(金额) as 金额 from (select * FROM [1日$B3:G103] union all select * FROM [2日$B3:G103] union all select * FROM [3日$B3:G103] union all select * FROM [4日$B3:G103] union all select * FROM [5日$B3:G103] union all select * FROM [6日$B3:G103] union all select * FROM [7日$B3:G103] union all select * FROM [8日$B3:G103] union all select * FROM [9日$B3:G103] union all select * FROM [10日$B3:G103] union all select * FROM [11日$B3:G103] union all select * FROM [12日$B3:G103] union all select * FROM [13日$B3:G103] union all select * FROM [14日$B3:G103] union all select * FROM [15日$B3:G103] union all select * FROM [16日$B3:G103] union all select * FROM [17日$B3:G103] union all select * FROM [18日$B3:G103] union all select * FROM [19日$B3:G103] union all select * FROM [20日$B3:G103] union all select * FROM [21日$B3:G103] union all select * FROM [22日$B3:G103] union all select * FROM [23日$B3:G103] union all select * FROM [24日$B3:G103] union all select * FROM [25日$B3:G103] union all select * FROM [26日$B3:G103] union all select * FROM [27日$B3:G103] union all select * FROM [28日$B3:G103] union all select * FROM [29日$B3:G103] union all select * FROM [30日$B3:G103] union all select * FROM [31日$B3:G103]) group by 品名,分类


group by  是对集合函数进行分组

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-3-13 13:27 | 显示全部楼层
万分感激,已经把我解救出来了。。。。继续努力学习。。。
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-11-1 12:29 , Processed in 0.031876 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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