ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

联合查询的SQL语句写出来总说有错,帮一下忙哈!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2005-4-26 16:00 | 显示全部楼层
以下是引用yoyo2008在2005-4-26 15:23:00的发言: "" as t1,"" 能解释一下是什么意思吗?

"" as t1的意思就是没有意思,主要是保持列数一致

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-26 16:20 | 显示全部楼层
你试过吗?我试了,但很乱的,能否再看看前面我的需求?谢谢!

TA的精华主题

TA的得分主题

发表于 2005-4-26 16:50 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

我看的眼睛都晕了,试试看吧

SELECT [Contract and Revenue(2002-2005)].[存档年Year], [Contract and Revenue(2002-2005)].[存档季Quarter], [Contract and Revenue(2002-2005)].[存档月份Month], [Contract and Revenue(2002-2005)].[区域/Area], [Contract and Revenue(2002-2005)].[客户编号/Subscriber Code], [Contract and Revenue(2002-2005)].[合同编号/ Contract Number], [Contract and Revenue(2002-2005)].[客户名称/ Subscriber Name], [Contract and Revenue(2002-2005)].[席位/小时License/Hour], [Contract and Revenue(2002-2005)].[月数/Months], [Contract and Revenue(2002-2005)].[合同金额/Contract Value], [Contract and Revenue(2002-2005)].[签约人/Handled By], [Contract and Revenue(2002-2005)].[开始日期Star Date], [Contract and Revenue(2002-2005)].[结束日期End Date], [Contract and Revenue(2002-2005)].[存档日期], [Contract and Revenue(2002-2005)].[回款金额Accepted], [Contract and Revenue(2002-2005)].[待收金额 Due], [Contract and Revenue(2002-2005)].[坏账Dead], [Contract and Revenue(2002-2005)].[备注 Remark] FROM [Contract and Revenue(2002-2005)]; union all

SELECT [Contract and Revenue(2002-2005)].[存档月份Month] & " 小计" AS 表达式1, "" as t1,[Contract and Revenue(2002-2005)].[存档月份Month] & " 小计" AS t2,"" as t3,"" as t4,"" as t5,"" as t6,"" as t7,"" as t8,"" as t9,"" as t10,"" as t11,"" as t12,"" as t13,"" as t14,"" as t15,"" as t16,Sum([Contract and Revenue(2002-2005)].[合同金额/Contract Value])AS ValueAll FROM [Contract and Revenue(2002-2005)] GROUP BY [Contract and Revenue(2002-2005)].[存档月份Month] & " 小计"

UNION ALL select "总计", "" as t1,"总计","" as t3,"" as t4,"" as t5,"" as t6,"" as t7,"" as t8,"" as t9,"" as t10,"" as t11,"" as t12,"" as t13,"" as t14,"" as t15,"" as t16,sum([合同金额/Contract Value]) from [Contract and Revenue(2002-2005)] ORDER BY [存档月份Month];

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-26 17:13 | 显示全部楼层

为什么有"2002-3 小计 "等等一行写了两次, 这样不好看的,怎么改?

小计和总计的数据怎么放在了备注里了呀,希望还在合同金额下面.

烦再看看

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-27 11:27 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-27 11:28 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2005-4-27 12:14 | 显示全部楼层

还有问题[em04]

若想继续按年小计,按季度小计,再总计,我已经照上面的格式做了,但显示"试图执行的查询中不包含作为合计函数一部分的特定表达式[Contract and Revenue(2002-2005)].[存档年Year] & "小计" 为什么??

以下是我加了想作按年小计的语句

UNION ALL SELECT [Contract and Revenue(2002-2005)].[存档年Year] & "小计" AS t1,"" as t2,"" as t3,"" as t4,"" as t5,"" as t6,"" as t7,"" as t8,"" as t9,Sum([Contract and Revenue(2002-2005)].[合同金额/Contract Value])AS t10,"" as t11,"" as t12,"" as t13,"" as t14,"" as t15,"" as t16,"" as t17,"" as t18 FROM [ Contract and Revenue(2002-2005)]

TA的精华主题

TA的得分主题

发表于 2005-4-27 13:22 | 显示全部楼层

SELECT [Contract and Revenue(2002-2005)].[存档年Year], [Contract and Revenue(2002-2005)].[存档季Quarter], [Contract and Revenue(2002-2005)].[存档月份Month], [Contract and Revenue(2002-2005)].[区域/Area], [Contract and Revenue(2002-2005)].[客户编号/Subscriber Code], [Contract and Revenue(2002-2005)].[合同编号/ Contract Number], [Contract and Revenue(2002-2005)].[客户名称/ Subscriber Name], [Contract and Revenue(2002-2005)].[席位/小时License/Hour], [Contract and Revenue(2002-2005)].[月数/Months], [Contract and Revenue(2002-2005)].[合同金额/Contract Value], [Contract and Revenue(2002-2005)].[签约人/Handled By], [Contract and Revenue(2002-2005)].[开始日期Star Date], [Contract and Revenue(2002-2005)].[结束日期End Date], [Contract and Revenue(2002-2005)].[存档日期], [Contract and Revenue(2002-2005)].[回款金额Accepted], [Contract and Revenue(2002-2005)].[待收金额 Due], [Contract and Revenue(2002-2005)].[坏账Dead], [Contract and Revenue(2002-2005)].[备注 Remark] FROM [Contract and Revenue(2002-2005)]; union all

SELECT [Contract and Revenue(2002-2005)].[存档月份Month] & " 小计" AS 表达式1, "" as t1,[Contract and Revenue(2002-2005)].[存档月份Month] & " 小计" AS t2,"" as t3,"" as t4,"" as t5,"" as t6,"" as t7,"" as t8,"" as t9,"" as t10,"" as t11,"" as t12,"" as t13,"" as t14,"" as t15,"" as t16,Sum([Contract and Revenue(2002-2005)].[合同金额/Contract Value])AS ValueAll FROM [Contract and Revenue(2002-2005)] GROUP BY [Contract and Revenue(2002-2005)].[存档月份Month] & " 小计"

union all

SELECT [Contract and Revenue(2002-2005)].[存档年Year] & "小计" AS 表达式1, "" as t1,[Contract and Revenue(2002-2005)].[存档年Year] & "小计" AS t2,"" as t3,"" as t4,"" as t5,"" as t6,"" as t7,"" as t8,"" as t9,"" as t10,"" as t11,"" as t12,"" as t13,"" as t14,"" as t15,"" as t16,Sum([Contract and Revenue(2002-2005)].[合同金额/Contract Value])AS ValueAll FROM [Contract and Revenue(2002-2005)] GROUP BY [Contract and Revenue(2002-2005)].[存档年Year] & "小计"

UNION ALL select "总计", "" as t1,"总计","" as t3,"" as t4,"" as t5,"" as t6,"" as t7,"" as t8,"" as t9,"" as t10,"" as t11,"" as t12,"" as t13,"" as t14,"" as t15,"" as t16,sum([合同金额/Contract Value]) from [Contract and Revenue(2002-2005)] ORDER BY [存档月份Month];

TA的精华主题

TA的得分主题

发表于 2005-4-27 13:24 | 显示全部楼层

我对access也不懂的

请问一下楼主,为什么这段SQL代码中有两个分号,不是分号代表结束的吗?

如果说用UNION ALL联合查询要分号的话,为什么后面几个就不需要分号呢?

请多多指教!!

TA的精华主题

TA的得分主题

发表于 2005-4-27 13:27 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册

测试了一下,前面几个分号加或不加并不影响最后的结果,期待高手指点一下

这几天陈版主不知上哪里去了,呵呵

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

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

GMT+8, 2024-12-24 07:43 , Processed in 0.043709 second(s), 6 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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