我有两个MySQL
表:
desc students;
+---------------------------+---------------+
| Field | Type |
+---------------------------+---------------+
| student_id | INT(11) |
| student_firstname | VARCHAR(255) |
| student_lastname | VARCHAR(255) |
+---------------------------+---------------+
desc studentabsence;
+---------------------------+---------------+
| Field | Type |
+---------------------------+---------------+
| student_id | INT(11) |
| student_absence_startdate | date |
| student_absence_enddate | date |
+---------------------------+---------------+
如果我运行以下查询:
SELECT
*
FROM
students s
INNER JOIN studentabsence sa
ON s.student_id = sa.student_id
WHERE s.student_id = '1'
我得到以下输出:
+------------+-------------------+-----------------+------------+---------------------------+-------------------------+
| student_id | student_firstname | student_lastname| student_id | student_absence_startdate | student_absence_enddate |
+------------+-------------------+-----------------+------------+---------------------------+-------------------------+
| 1 | John | Doe | 1 | 2012-08-01 | 2012-08-08 |
+------------+-------------------+-----------------+------------+---------------------------+-------------------------+
现在,我有<form>
用户可以选择学生和日期范围。我想知道是否有可能将用户选择的两个日期与数据库值进行比较,并且如果匹配回显该学生拥有数据的该范围之间的所有工作日。
因此,如果用户发布以下表单,请使用上面的示例:
student_id = '1'
student_absence_startdate = '2012-08-02'
student_absence_enddate = '2012-08-06'
我想echo
:
2012-08-02
2012-08-03
2012-08-06
任何指向正确方向的人都非常感激。
答案 0 :(得分:0)
我仅在查询的基础上发布此回复。此外,如果您将数据类型保留为日期,则可以帮助您。
SELECT * FROM students s
INNER JOIN studentabsence sa ON s.student_id = sa.student_id
AND s.student_id = '1'
AND student_absence_startdate >= 2012-08-02
AND student_absence_enddate < 2012-08-06