1

我有一个学生考勤系统程序,并在mysql表上记录保存,如果存在则为1,如果不存在则为0

表 -> 出勤率

uid  date       status  App
1   01/07/2013  1   
1   01/07/2013  1   
1   01/07/2013  1   
1   01/07/2013  0   
1   01/07/2013  0   
1   02/07/2013  1   
1   02/07/2013  0   
1   02/07/2013  1   
1   02/07/2013  1   
1   02/07/2013  1   
1   03/07/2013  0   
1   03/07/2013  0   
1   03/07/2013  1   
1   03/07/2013  1   
1   03/07/2013  1   
1   04/07/2013  0   
1   04/07/2013  1   
1   04/07/2013  1   
1   04/07/2013  1   
1   04/07/2013  1   

我还有一张桌子,学生可以在其中提交他们的休假申请,如下所示

表 -> 应用程序

 id  uid    from            to           status
 1   1    04/07/2013    07/07/2013  approved
 2   1    11/07/2013    12/07/2013  rejected

我希望如果状态设置为已批准,那么将在“出席”表中搜索申请中给出的从 7 月 4 日到 7 月 7 日的日期范围,并且无论找到状态为 0 的日期,它都会将 1 添加到“应用”列并忽略不出席的日期。

4

3 回答 3

3
UPDATE attendance  d
  JOIN application p
    ON d.uid = p.uid
   AND d.date BETWEEN p.from AND p.to
SET    d.status = 1
WHERE  p.status = 'approved'
于 2013-07-12T13:39:41.710 回答
3
UPDATE attendance  d
  JOIN application p
    ON d.uid = p.uid
   AND d.date BETWEEN p.from AND p.to
   AND p.status = 'approved'
SET    d.app = 1
WHERE  d.status = 0
于 2013-07-12T14:09:16.063 回答
0

这应该做你想要的:

UPDATE attendance a
    Set a.app=1
    WHERE a.uid IN
        (select z.uid
            FROM application z
            WHERE z.status='approved'
                AND a.date BETWEEN z.from and z.to);
于 2013-07-12T13:41:13.557 回答