gpt4 book ai didi

ms-access - MS Access 错误 :the number of columns in the two selected tables does not match

转载 作者:行者123 更新时间:2023-12-04 21:46:26 25 4
gpt4 key购买 nike

我在 MS Access 查询中遇到此错误:The number of columns in the two selected tables or queries of a union query do not match.
列数完全匹配,当我运行 UNION 查询时,一次选择任意 2 个集合,它工作正常。当我在查询中包含超过 2 个选择时,它会显示此错误。

SELECT  "Applied" as Application_Status, Count(*) AS [CountOfApplication Status]
FROM [EDB Applicants - ALL]
WHERE [EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Dec Date]>Date()-366

UNION

SELECT "Hold" as Application_Status, Count(*) AS [CountOfApplication Status]
FROM [EDB Applicants - ALL]
WHERE [EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Dec Date]<=Date()-366 And [EDB Applicants - ALL].[Application Status]="Hold"

UNION

SELECT "Withdraw" as Application_Status, Count(*) AS [CountOfApplication Status]
FROM [EDB Applicants - ALL]
WHERE [EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Date of Enrollment Change]<=Date()-366 And [EDB Applicants - ALL].[Application Status] In ("Declined","Withdrew Application","Withdrew After Enrollment")

最佳答案

我不知道您的原始问题的原因,但您可以重写您的查询以消除联合:

select Application_Status, COUNT(*)
from (select (case when [EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Dec Date]>Date()-366
then 'Applied'
when [EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Dec Date]<=Date()-366 And [EDB Applicants - ALL].[Application Status]="Hold"
then 'Hold'
when [EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Date of Enrollment Change]<=Date()-366 And [EDB Applicants - ALL].[Application Status] In ("Declined","Withdrew Application","Withdrew After Enrollment")
then 'Withdraw'
end) as Application_Status, [EDB Applicants - ALL].*
from [EDB Applicants - ALL]
) t
where Application_Status is not null
group by Application_Status

没错,在 MS Access 中你必须使用 IIF(),但同样的想法也适用:
select Application_Status, COUNT(*)
from (select iif([EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Dec Date]>Date()-366,
'Applied',
iif([EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Dec Date]<=Date()-366 And [EDB Applicants - ALL].[Application Status]="Hold",
'Hold',
iif([EDB Applicants - ALL].[Application Year].Value Like "2012" And [EDB Applicants - ALL].[Application Date]<=Date()-366 And [EDB Applicants - ALL].[Date of Enrollment Change]<=Date()-366 And [EDB Applicants - ALL].[Application Status] In ("Declined","Withdrew Application","Withdrew After Enrollment")
'Withdraw', '')))) as Application_Status, [EDB Applicants - ALL].*
from [EDB Applicants - ALL]
) t
where Application_Status <> ''
group by Application_Status

关于ms-access - MS Access 错误 :the number of columns in the two selected tables does not match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13689169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com