我想问一下如何改进访问代码

时间:2017-01-25 04:13:45

标签: sql ms-access ms-access-2007

SELECT userinfo.NAME
    ,MONTH
    ,YEAR
    ,(
        SELECT FORMAT((min(checkinout.checktime)), "hh:mm:ss AMPM")
        FROM checkinout
        WHERE checktype = "i"
            AND format(checkinout.checktime, "dd") = (tbldays.days)
            AND format(checkinout.checktime, "am/pm") = ("am")
            AND format(checkinout.checktime, "mmmm") = MONTH
            AND format(checkinout.checktime, "yyyy") = YEAR
        ) AS TIMEIN_AM
    ,(
        SELECT FORMAT((max(checkinout.checktime)), "hh:mm:ss AMPM")
        FROM checkinout
        WHERE checktype = "o"
            AND format(checkinout.checktime, "dd") = (tbldays.days)
            AND format(checkinout.checktime, "am/pm") = ("am")
            AND format(checkinout.checktime, "mmmm") = MONTH
            AND format(checkinout.checktime, "yyyy") = YEAR
        ) AS TIMEOUT_AM
    ,(
        SELECT FORMAT((min(checkinout.checktime)), "hh:mm:ss AMPM")
        FROM checkinout
        WHERE checktype = "i"
            AND format(checkinout.checktime, "dd") = (tbldays.days)
            AND format(checkinout.checktime, "am/pm") = ("pm")
            AND format(checkinout.checktime, "mmmm") = MONTH
            AND format(checkinout.checktime, "yyyy") = YEAR
        ) AS TIMEIN_PM
    ,(
        SELECT FORMAT((max(checkinout.checktime)), "hh:mm:ss AMPM")
        FROM checkinout
        WHERE checktype = "o"
            AND format(checkinout.checktime, "dd") = (tbldays.days)
            AND format(checkinout.checktime, "am/pm") = ("pm")
            AND format(checkinout.checktime, "mmmm") = MONTH
            AND format(checkinout.checktime, "yyyy") = YEAR
        ) AS TIMEOUT_PM
FROM checkinout
    ,userinfo
    ,tbldays
WHERE userinfo.userid = checkinout.userid
    AND userinfo.NAME = NAME_
GROUP BY tbldays.days
    ,userinfo.NAME
    ,checkinout.checktime
ORDER BY tbldays.days;

检查时间表,然后是Userinfo的一般信息表,然后是tbldays表,从1到31天

0 个答案:

没有答案