我有一个 Access 2007 数据库,可以跟踪文档随时间的进展。进展是这样的:
- 已创建
- 送审
- 已审核
- 发送审批
- 得到正式认可的
我为文档状态的更改创建了一个历史表,其中包含如下列:
hist_id doc_id month step status datestamp
我创建了一个返回月底状态的查询,如下所示:
SELECT doc_id, month, step, status, datestamp
FROM hist
WHERE (((hist.datestamp) In
(
Select Top 1 h.[datestamp]
From hist as h
Where h.[doc_id] = hist.[doc_id] and h.[month] = hist.[month]
Order By h.[datestamp] DESC))
)
ORDER BY month, doc_id DESC;
要得到....
doc_id month step status datestamp
a 2011-01 2 sent for review 18/01/2011
b 2011-02 1 created 01/02/2011
a 2011-02 3 reviewed 19/02/2011
c 2011-03 1 created 07/03/2011
d 2011-03 1 created 08/03/2011
e 2011-06 1 created 14/06/2011
f 2011-07 1 created 05/07/2011
g 2011-07 4 sent for approval 18/07/2011
h 2011-07 2 sent for review 14/07/2011
f 2011-08 3 reviewed 29/08/2011
g 2011-08 5 approved 17/08/2011
h 2011-08 1 created 10/08/2011
e 2011-09 3 reviewed 17/09/2011
但我真正需要的是我的查询,以便在几个月内返回状态没有改变的文档。例如, documenta
的状态变为reviewed
on 19/02/2011
,但这是它最后一次出现在上面的结果中。它实际上应该在之后的每个月出现,reviewed
直到后来变成sent for approval
.
所以我正在尝试修改我的查询(或查询上面的查询)以提供如下结果......
doc_id month step status datestamp
a 2011-01 2 sent for review 18/01/2011
a 2011-02 3 reviewed 19/02/2011
b 2011-02 1 created 01/02/2011
a 2011-03 3 reviewed 19/02/2011
b 2011-03 1 created 01/02/2011
c 2011-03 1 created 07/03/2011
d 2011-03 1 created 08/03/2011
a 2011-04 3 reviewed 19/02/2011
b 2011-04 1 created 01/02/2011
c 2011-04 1 created 07/03/2011
d 2011-04 1 created 08/03/2011
a 2011-05 3 reviewed 19/02/2011
b 2011-05 1 created 01/02/2011
c 2011-05 1 created 07/03/2011
d 2011-05 1 created 08/03/2011
a 2011-06 3 reviewed 19/02/2011
b 2011-06 1 created 01/02/2011
c 2011-06 1 created 07/03/2011
d 2011-06 1 created 08/03/2011
e 2011-06 1 created 14/06/2011
a 2011-07 3 reviewed 19/02/2011
b 2011-07 1 created 01/02/2011
c 2011-07 1 created 07/03/2011
d 2011-07 1 created 08/03/2011
e 2011-07 1 created 14/06/2011
f 2011-07 1 created 05/07/2011
g 2011-07 4 sent for appr 18/07/2011
h 2011-07 2 sent for rev 14/07/2011
a 2011-08 3 reviewed 19/02/2011
b 2011-08 1 created 01/02/2011
c 2011-08 1 created 07/03/2011
d 2011-08 1 created 08/03/2011
e 2011-08 1 created 14/06/2011
f 2011-08 3 reviewed 29/08/2011
g 2011-08 5 approved 17/08/2011
h 2011-08 1 created 10/08/2011
a 2011-09 3 reviewed 19/02/2011
b 2011-09 1 created 01/02/2011
c 2011-09 1 created 07/03/2011
d 2011-09 1 created 08/03/2011
e 2011-09 1 reviewed 17/09/2011
f 2011-09 3 reviewed 29/08/2011
g 2011-09 5 approved 17/08/2011
h 2011-09 1 created 10/08/2011
谢谢你的帮助......我真的不知道从哪里开始。