我将从发布我的查询开始...
SELECT [copyright status],
sum(IIF(layer='key info',1,0)) AS [Key Info],
sum(IIF(layer='approaches',1,0)) AS [Approaches],
sum(IIF(layer='research',1,0)) AS [Research]
FROM resources
GROUP BY [copyright status]
UNION
SELECT [lw status],
sum(IIF(layer='key info',1,0)) AS [Key Info],
sum(IIF(layer='approaches',1,0)) AS [Approaches],
sum(IIF(layer='research',1,0)) AS [Research]
FROM resources
WHERE [lw status] = 'In Reserve'
GROUP BY [lw status]
UNION
SELECT [lw status],
sum(IIF(layer='key info',1,0)) AS [Key Info],
sum(IIF(layer='approaches',1,0)) AS [Approaches],
sum(IIF(layer='research',1,0)) AS [Research]
FROM resources
WHERE [lw status] = 'Published'
GROUP BY [lw status];
(希望这很容易阅读)
它按我的意图工作,但是我想在查询中再添加一个函数。
在第一个SELECT
查询之后,我想添加一个额外的查询,该查询总计三个总和(关键信息、方法、研究)中的每一个。我尝试添加的语法如下:
<Previous Query>
UNION
SELECT,
sum(IIF(layer='key info',1,0)) AS [Key Info],
sum(IIF(layer='approaches',1,0)) AS [Approaches],
sum(IIF(layer='research',1,0)) AS [Research]
FROM resources
UNION
<Next Query>
但是,当我尝试运行它时,我收到一条错误消息,显示“联合查询的两个选定查询表中的列数不匹配”。
我不确定我是否对此过于雄心勃勃。
此外,是否有更有效的方式来格式化初始查询?
如果有什么不同,layer、copyright status 和 lw status 中的值分别存储在单独的表中,并通过表格设计模式中的组合框绘制到资源表中。我正在使用 Access 2003。
如果需要更多信息,请告诉我。
谢谢。