我是这里的新手,所以我很抱歉立即提出一个(我认为是)困难的问题,但我被困住了,希望你们能为我提供帮助。我已为其附上一张图像,该图像显示了我的表设计以及它们之间的关系(MS Access的屏幕截图)。这可能有助于阅读我的问题时看到:
我正在尝试编写一个查询,该查询给出了“客户参与”表中的“会计年度结束”,并返回当前年份(会计年度结束)“客户K1”中不存在的“投资名称”字段/ Tax Report”列表中列出了上一会计年度末存在的DID / DO。
基本上,我想要一个列表,其中存在去年的投资名称列表,而今年没有报告/列表。
请原谅我的基本语法技能或我可能犯的任何错误。
在此先感谢您提供的任何帮助!
我现在的SQL代码是:
PARAMETERS [CURRENT FISCAL YEAR] DateTime, [COMPARATIVE FISCAL YEAR] DateTime;
SELECT Investments.[Investment Name], [Client Engagement].[Fiscal Year End]
FROM Investments INNER JOIN ([Investment Year] INNER JOIN ([Client Engagement] INNER JOIN [Client K1/Tax Report] ON [Client Engagement].EngagementID = [Client K1/Tax Report].[Client Engagement ID]) ON [Investment Year].[Investment FS ID] = [Client K1/Tax Report].[Investment FS ID]) ON Investments.[Investment Name] = [Investment Year].[Investment Name]
WHERE ((([Client Engagement].[Fiscal Year End])=[CURRENT FISCAL YEAR])) NOT IN
(
SELECT Investments.[Investment Name], [Client Engagement].[Fiscal Year End]
FROM Investments INNER JOIN ([Investment Year] INNER JOIN ([Client Engagement] INNER JOIN [Client K1/Tax Report] ON [Client Engagement].EngagementID = [Client K1/Tax Report].[Client Engagement ID]) ON [Investment Year].[Investment FS ID] = [Client K1/Tax Report].[Investment FS ID]) ON Investments.[Investment Name] = [Investment Year].[Investment Name]
WHERE ((([Client Engagement].[Fiscal Year End])=[COMPARATIVE FISCAL YEAR]))
)
经过格式化以提高可读性:
PARAMETERS [CURRENT FISCAL YEAR] DATETIME
,[COMPARATIVE FISCAL YEAR] DATETIME;
SELECT Investments.[Investment Name]
,[Client Engagement].[Fiscal Year End]
FROM Investments
INNER JOIN (
[Investment Year] INNER JOIN (
[Client Engagement] INNER JOIN [Client K1/Tax Report] ON [Client Engagement].EngagementID = [Client K1/Tax Report].[Client Engagement ID]
) ON [Investment Year].[Investment FS ID] = [Client K1/Tax Report].[Investment FS ID]
) ON Investments.[Investment Name] = [Investment Year].[Investment Name]
WHERE ((([Client Engagement].[Fiscal Year End]) = [CURRENT FISCAL YEAR])) NOT IN (
SELECT Investments.[Investment Name]
,[Client Engagement].[Fiscal Year End]
FROM Investments
INNER JOIN (
[Investment Year] INNER JOIN (
[Client Engagement] INNER JOIN [Client K1/Tax Report] ON [Client Engagement].EngagementID = [Client K1/Tax Report].[Client Engagement ID]
) ON [Investment Year].[Investment FS ID] = [Client K1/Tax Report].[Investment FS ID]
) ON Investments.[Investment Name] = [Investment Year].[Investment Name]
WHERE ((([Client Engagement].[Fiscal Year End]) = [COMPARATIVE FISCAL YEAR]))
)