我目前有一个产生3列的SQL语句:
[Review Date] [Total Reviews] [Reviewed By]
10/24/2001 16 Jane
10/24/2001 1 Bob
10/24/2001 2 Chloe
09/20/2001 17 Jane
09/20/2001 34 Bob
09/20/2001 86 Chloe
02/04/2001 14 Jane
02/04/2001 3 Bob
02/04/2001 41 Chloe
SQL看起来像这样(以获得上述输出):
SELECT
[Review Results].[Review Date],
count([Review Results].[Reviewed By]) as [Total Reviews],
[Review Results].[Reviewed By]
FROM
[Review Results]
GROUP BY [Review Results].[Review Date], [Review Results].[Reviewed By]
ORDER BY [Review Results].[Review Date]
我想要做的是在[Home_Days_table]中加入另一个表。该表如下所示:
[Reviewed By] [WFH Date]
Jane 10/12/2011
Jane 07/11/2010
Bob 04/09/2002
Jane 01/01/2007
我正在寻找以上查询来填充[Home_Days_Table]中的[WFH Date]字段,以便在[Results Review]之间匹配每条记录。[Review Date]& [结果回顾]。[评论者]与[Home_Days_Table]。[评论者]& [Home_Days_Table]。[WFH日期]。我想显示上面原始SQL中的所有记录,并附加满足此条件的列。
除了上述内容之外,我还希望按照给定的方式执行查询,但添加另一个日期字段。我使用的查询是:
SELECT
[Review Results].[Review Date],
count([Review Results].[Reviewed By]) as [Total Reviews],
[Review Results].[Reviewed By],
[Home_Days_table].[WFH Date]
FROM [Review Results]
LEFT JOIN [Home_Days_table]
ON [Review Results].[Reviewed By]=[Home_Days_table].[Reviewed By]
AND [Review Results].[Review Date]=[Home_Days_table].[WFH Date]
GROUP BY
[Review Results].[Review Date],
[Review Results].[Reviewed By],
[Home_Days_table].[WFH Date]
ORDER BY [Review Results].[Review Date]
以上查询回答了原始问题,但我想在[WFH日期]上添加另一个名为[Summer Days]的列。这个想法与原始问题相同,但我正在寻找查询现在填充[Home_Days_Table]中的[WFH Date]字段和[Home_Days_Table]中的[Summer Days]字段,用于每个匹配的记录在[结果审查]之间。[审查日期]& [结果回顾]。[评论者]与[Home_Days_Table]。[评论者]& [Home_Days_Table]。[WFH日期]和[结果审核]。[审核日期]& [结果回顾]。[评论者]与[Home_Days_Table]。[评论者]& [Home_Days_Table]。[夏日]。
有人可以帮忙吗?
答案 0 :(得分:1)
像...一样的东西?
SELECT
[Review Results].[Review Date],
count([Review Results].[Reviewed By]) as [Total Reviews],
[Review Results].[Reviewed By],
[Home_Days_table].[WFH Date]
FROM [Review Results]
LEFT JOIN [Home_Days_table]
ON [Review Results].[Reviewed By]=[Home_Days_table].[Reviewed By}
AND [Review Results].[Review Date]=[Home_Days_table].[WFH Date]
GROUP BY
[Review Results].[Review Date],
[Review Results].[Reviewed By],
[Home_Days_table].[WFH Date]
ORDER BY [Review Results].[Review Date]