Ms access msaccess将最近的匹配记录从一个表连接到另一个表
我想要的结果 +--------+-------------+------------+--------+ | Tag | most_recent | Comment | Author | +--------+-------------+------------+--------+ | TAG001 | 2015-07-23 | Something3 | AM | | TAG002 | 2015-07-25 | Something5 | BN | +--------+-------------+------------+--------+ 结果1 +--------+-------------+ | Tag | most_recent | +--------+-------------+ | TAG001 | 2015-07-23 | | TAG002 | 2015-07-25 | +--------+-------------+ 结果2 +--------+-------------+------------+ | Tag | most_recent | Comment | +--------+-------------+------------+ | TAG001 | 2015-07-22 | Something1 | | TAG001 | 2015-07-23 | Something3 | | TAG002 | 2015-07-23 | Something2 | | TAG002 | 2015-07-23 | Something4 | | TAG002 | 2015-07-25 | Something5 | +--------+-------------+------------+ 结果:查询表达式中缺少运算符的语法错误 问题4 从此处修改: 结果:联接时出现语法错误 运气不太好…提前谢谢你Ms access msaccess将最近的匹配记录从一个表连接到另一个表,ms-access,join,ms-access-2010,left-join,Ms Access,Join,Ms Access 2010,Left Join,我想要的结果 +--------+-------------+------------+--------+ | Tag | most_recent | Comment | Author | +--------+-------------+------------+--------+ | TAG001 | 2015-07-23 | Something3 | AM | | TAG002 | 2015-07-25 | Something5 | BN | +-------
谢谢。在Access 2010中,以下内容似乎适用于我: 选择c.标记,c.日期创建为最新,c.注释,c.作者 从…起 选择标记,MaxDate创建为MaxDate 根据评论 按标签分组 医学博士 内连接 作为c的评论 在c.Tag=md.Tag和c.DateCreated=md.MaxDate上
SELECT Comments.[Tag], Max(Comments.[DateCreated]) AS most\_recent
FROM Comments
GROUP BY Comments.[Tag];
+--------+-------------+
| Tag | most_recent |
+--------+-------------+
| TAG001 | 2015-07-23 |
| TAG002 | 2015-07-25 |
+--------+-------------+
SELECT Comments.[Tag], Max(Comments.[DateCreated]) AS most\_recent
FROM Comments
GROUP BY Comments.[Tag];
+--------+-------------+------------+
| Tag | most_recent | Comment |
+--------+-------------+------------+
| TAG001 | 2015-07-22 | Something1 |
| TAG001 | 2015-07-23 | Something3 |
| TAG002 | 2015-07-23 | Something2 |
| TAG002 | 2015-07-23 | Something4 |
| TAG002 | 2015-07-25 | Something5 |
+--------+-------------+------------+
SELECT Status.\*,Comments.\*
FROM Status S
LEFT JOIN Comments C ON S.tag = C.tag
JOIN(SELECT x.tag, MAX(x.DateCreated) AS MaxCommentDate FROM Comments x
GROUP BY x.tag) y ON y.tag = x.tag AND y.MaxCommentDate = x.DateCreated
SELECT
Status.\*,Comments.\*
FROM Status S
LEFT JOIN
(
Comments C
INNER JOIN
(
SELECT
x.tag, MAX(x.DateCreated) AS MaxCommentDate
FROM
Comments x
GROUP BY
x.tag
)
y
ON y.tag = x.tag
AND y.MaxCommentDate = x.DateCreated
)
ON S.tag = C.tag;