|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
嗯,的确是个问题,这样解决是否可以?
1)增加一张辅助表,见Sheet3
2)修改SQL语句为
SELECT A.INCC,A.City,A.Dept,A.Mo,(SELECT SUM(数量) FROM [Sheet2$] where 公司=A.INCC and 城市=A.City and 部门=A.Dept and Month(月份)<=A.Mo) as QTY,(SELECT SUM(金额) FROM [Sheet2$] where 公司=A.INCC and 城市=A.City and 部门=A.Dept and Month(月份)<=A.Mo) as Sales FROM (SELECT DISTINCT A1.公司 as INCC,A1.城市 as City,A1.部门 as Dept,A2.Mo as Mo FROM [Sheet2$] as A1,[Sheet3$] as A2) as A
见附件。
数据透视表-求SQL语句.rar
(42.21 KB, 下载次数: 26)
(这样的SQL速度好慢,已经黔驴技穷了,:) ,还不如用公式来解决 |
|