MS Access 2007中的查询应该是什么

时间:2013-03-11 08:29:37

标签: ms-access group-by where-clause correlated-subquery

有一张表有coulmns:
ID,BOOKID,名称,dateofentry,状态。

需要对书的书籍和最后的dateofentry以及书的状态,即R的结果 (R-返回,NR-不返回)

例如 输入: -

id bookid subject dateofentry Status
1   10      math   10-11-2012 NR
2   10      math   1-12-2012  R
3   110     math   1-12-2012  NR
4   110     math   10-12-2012 NR
5   102     math   10-11-2012 NR
6   102     math   1-12-2012  R
7   105     math   10-12-2012 NR
8   105     math   17-12-2012 NR
9   106     math   11-12-2012 NR
10  106     math   14-12-2012 R

输出: -

10   math 1-12-2012 R
102  math 1-12-2012 R
106  math 14-12-2012 R

该查询应该是什么

先谢谢

我试过了: -

SELECT t.bookid, t.satus, r.MaxDate
FROM (SELECT bookid, MAX(dateofentry) as MaxDate
      FROM TempLogs
      GROUP BY bookid) r
INNER JOIN Logs t ON t.bookid = r.bookid AND t.dateofentry = r.MaxDate where status="R" 

但是我收到了一些语法错误,而且它无法正常工作。

1 个答案:

答案 0 :(得分:1)

看起来语法错误是因为您使用了2个不同的表名。在子查询中,您使用的是表TempLogs,但在外部查询中,您可以引用表Logs。除此之外,您尝试实现的实际查询和方法似乎是正确的。