我有一个查询,我希望mstemp表的所有记录都必须根据给定的条件显示。

SELECT
    mstEmp.empname, InDate, dailyattendance.InTime,
    dailyattendance.OutTime, mstEmp.teamtype
FROM
    mstEmp
LEFT JOIN
    dailyattendance ON (dailyattendance.HolderName = mstEmp.empname )
WHERE
    mstEmp.teamtype = '$chk'
    AND (InDate BETWEEN '$from' AND '$to' )
ORDER BY
    InDate ASC

但这个查询似乎不起作用。

最佳答案

试试这个:

SELECT mstEmp.empname, InDate, dailyattendance.InTime,
       dailyattendance.OutTime, mstEmp.teamtype
FROM mstEmp
  LEFT JOIN dailyattendance
    ON (dailyattendance.HolderName = mstEmp.empname ) AND (InDate BETWEEN '$from' AND '$to' )
WHERE mstEmp.teamtype = '$chk'
ORDER BY InDate ASC

09-05 15:57