如何获取今天记录的最小值(时间)和前一天记录的最大值(时间)
使用MS Access数据库
我想显示今天记录的最小值(时间)和前一天记录的最大值(时间)
表
PERSON ID CARDEVENTDATE CARDEVENTTIME
5008 20090805 080000
5008 20090805 140000
5008 20090809 180000
5008 20090809 220000
5008 20090813 090000
5008 20090813 200000
5008 20090818 110000
5008 20090818 232200
3405 20090805 080000
3405 20090805 180000
3405 20090809 070000
3405 20090809 230000
3010 20080806 090000
3010 20080806 230000
3010 20080810 100000
3010 20080810 160000
等等...
从上表中我想显示今天的最小值(时间)和前一天的最大值(时间
) day 表示不是昨天,而是特定人员 ID 的前一个卡片事件时间。
我正在使用子查询。
我正在使用下面提到的查询。
"SELECT PERSONID, CARDEVENTDATE, MIN (CARDEVENTTIME) AS INTIME,
MAX (CARDEVENTTIME) AS OUTTIME FROM (SELECT T_PERSON.PERSONID,
T_CARDEVENT.CARDEVENTDATE, T_CARDEVENT.CARDEVENTTIME
FROM (T_TITLE INNER JOIN T_PERSON ON T_TITLE.TITLECODE = T_PERSON.TITLECODE)
INNER JOIN T_CARDEVENT ON T_PERSON.PERSONID = T_CARDEVENT.PERSONID
WHERE T_CARDEVENT.CARDEVENTDATE BETWEEN '" & sdate & "' AND '" & edate & "'
ORDER BY T_PERSON.TITLECODE) GROUP BY PERSONID, CARDEVENTDATE))"
但我无法获得前一天的最大(时间)。 我想获取特定人员 ID 的今天最小(时间)和前一天最大(时间)。
前一天意味着不是昨天,而是特定人员 ID 的前一个卡片事件时间。
预期输出。
PERSON ID CARDEVENTDATE MIN TIME CARDEVENTDATE MAX TIME
5008 20090818 110000 20090813 200000
5008 20090813 090000 20090809 220000
5008 20090809 180000 20090805 140000
3405 20090809 070000 20090805 180000
3010 20080810 100000 20080806 230000
等等...
需要查询帮助。
Using MS Access database
I want to display today record min (time) and previous day record max (time)
Table
PERSON ID CARDEVENTDATE CARDEVENTTIME
5008 20090805 080000
5008 20090805 140000
5008 20090809 180000
5008 20090809 220000
5008 20090813 090000
5008 20090813 200000
5008 20090818 110000
5008 20090818 232200
3405 20090805 080000
3405 20090805 180000
3405 20090809 070000
3405 20090809 230000
3010 20080806 090000
3010 20080806 230000
3010 20080810 100000
3010 20080810 160000
and so on...
From the above table I want to display Today min (time) and previous day max (time)
Previous day means not yesterday, previous cardeventtime for the particular person id.
Am using sub queries.
I am using below mentioned query.
"SELECT PERSONID, CARDEVENTDATE, MIN (CARDEVENTTIME) AS INTIME,
MAX (CARDEVENTTIME) AS OUTTIME FROM (SELECT T_PERSON.PERSONID,
T_CARDEVENT.CARDEVENTDATE, T_CARDEVENT.CARDEVENTTIME
FROM (T_TITLE INNER JOIN T_PERSON ON T_TITLE.TITLECODE = T_PERSON.TITLECODE)
INNER JOIN T_CARDEVENT ON T_PERSON.PERSONID = T_CARDEVENT.PERSONID
WHERE T_CARDEVENT.CARDEVENTDATE BETWEEN '" & sdate & "' AND '" & edate & "'
ORDER BY T_PERSON.TITLECODE) GROUP BY PERSONID, CARDEVENTDATE))"
But am not able to get previous day max (time). I want to get Today min (time) and previous day Max (time) for the particular person id.
Previous day means not yesterday, previous cardeventtime for the particular person id.
Expected Output.
PERSON ID CARDEVENTDATE MIN TIME CARDEVENTDATE MAX TIME
5008 20090818 110000 20090813 200000
5008 20090813 090000 20090809 220000
5008 20090809 180000 20090805 140000
3405 20090809 070000 20090805 180000
3010 20080810 100000 20080806 230000
and so on...
Need Query Help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
废弃最后一个答案。
假设您将查询保存为 DAYMINMAX。
您需要创建另一个查询:
该查询为您提供每个人的一个日期及其前一个日期。 我们将其命名为 DAYPREVNEW。 现在您还需要另一个查询(您想要的查询):
由于您的原始查询被多次引用以创建所需的答案,因此最好将其创建为单独的查询,而不是使用子查询。
Scrap last answer.
Let's say you saved your query as DAYMINMAX.
You'll need to create another query:
That query gives you one date and its previous date per person. Let's name it DAYPREVNEW. Now you'll need yet another one query (the one you want):
As your original query gets referenced so many times to create the answer needed, it is best to create it as a separate query than using sub-queries.