你自己不想动手写吧!哪有一条sql语句输出这么多要求的

解决方案 »

  1.   

    要是我的话,我觉得这数据库设计的都不好,
    你上下班这个逻辑很简单
    上班8:30,下班17:40,这样的话,我就不会把上下班分成两个数据,
    我会这样设计考勤表 attendance
    attendance_start attendance_end字段  设置默认值 0
    attendance_type 设置默认值 0(未迟到早退)
    ps:做个判读迟到早退的逻辑再入数据库attendance_id  |attendance_date  |attendance_start  |attendance_end  |attendance_type (迟到为1,早退为2,迟到&再退3)
    1                       2014-10-10           8:27:23                  17:58:22               0
    2                       2014-10-11           8:27:23                  17:58:22               0
    这样的话
    1)查询上班未打卡日期
    select * from attendance where attendance_start=0
    2)查询下班未打卡日期
    select * from attendance where attendance_end=0
    3)迟到&早退几分钟
    select * from attendance where attendance_type=1
    select * from attendance where attendance_type=2
    select * from attendance where attendance_type=3
    那8:30 17:40 与 考勤时间计算 就能得到迟到&早退几分钟