SELECT USERINFO.Name,
FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy") AS DATE_IN, FORMAT((Min(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEIN_am, FORMAT((Max(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEOUT_pm, FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy hh:mm") AS DATE_SORT
FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID=USERINFO.USERID
WHERE (CHECKINOUT.CHECKTIME>=DATEVALUE(PERIOD_START) And CHECKINOUT.CHECKTIME<DATEADD("d",1,PERIOD_END))
GROUP BY CHECKINOUT.USERID, USERINFO.Name, USERINFO.SSN, DateValue(CHECKINOUT.CHECKTIME), USERINFO.Badgenumber
HAVING (((USERINFO.Badgenumber)<"8000"))
ORDER BY USERINFO.Name, Min(CHECKINOUT.CHECKTIME);
这个查询是针对am的timein和pm的超时
SELECT USERINFO.Name, FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy") AS DATE_IN, FORMAT((Min(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEOUT_am, FORMAT((Max(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEIN_pm, FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy hh:mm") AS DATE_SORT
FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID=USERINFO.USERID
WHERE (CHECKINOUT.CHECKTIME>=DATEVALUE(PERIOD_START) And CHECKINOUT.CHECKTIME<DATEADD("d",1,PERIOD_END) And FORMAT(CHECKINOUT.CHECKTIME,"hh:mm")>"12:00" And FORMAT(CHECKINOUT.CHECKTIME,"hh:mm")<"13:00")
GROUP BY CHECKINOUT.USERID, USERINFO.Name, USERINFO.SSN, DateValue(CHECKINOUT.CHECKTIME), USERINFO.Badgenumber, FORMAT(CHECKINOUT.CHECKTIME,"dd")
HAVING (((USERINFO.Badgenumber)<"8000"))
ORDER BY USERINFO.Name, Min(CHECKINOUT.CHECKTIME);
此查询是针对am的超时,以及针对pm的timein
答案 0 :(得分:0)
SELECT *
FROM (
SELECT USERINFO.Name,
FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy") AS DATE_IN, FORMAT((Min(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEIN_am, FORMAT((Max(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEOUT_pm, FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy hh:mm") AS DATE_SORT
FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID=USERINFO.USERID
WHERE (CHECKINOUT.CHECKTIME>=DATEVALUE(PERIOD_START) And CHECKINOUT.CHECKTIME<DATEADD("d",1,PERIOD_END))
GROUP BY CHECKINOUT.USERID, USERINFO.Name, USERINFO.SSN, DateValue(CHECKINOUT.CHECKTIME), USERINFO.Badgenumber
HAVING (((USERINFO.Badgenumber)<"8000"))
UNION ALL
SELECT USERINFO.Name, FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy") AS DATE_IN, FORMAT((Min(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEOUT_am, FORMAT((Max(CHECKINOUT.CHECKTIME))," hh:mm") AS TIMEIN_pm, FORMAT((Min(CHECKINOUT.CHECKTIME)),"dd-mmm-yyyy hh:mm") AS DATE_SORT
FROM CHECKINOUT INNER JOIN USERINFO ON CHECKINOUT.USERID=USERINFO.USERID
WHERE (CHECKINOUT.CHECKTIME>=DATEVALUE(PERIOD_START) And CHECKINOUT.CHECKTIME<DATEADD("d",1,PERIOD_END) And FORMAT(CHECKINOUT.CHECKTIME,"hh:mm")>"12:00" And FORMAT(CHECKINOUT.CHECKTIME,"hh:mm")<"13:00")
GROUP BY CHECKINOUT.USERID, USERINFO.Name, USERINFO.SSN, DateValue(CHECKINOUT.CHECKTIME), USERINFO.Badgenumber, FORMAT(CHECKINOUT.CHECKTIME,"dd")
HAVING (((USERINFO.Badgenumber)<"8000"))
) DB
ORDER BY DB.Name, Min(DB.CHECKTIME)