从这个数据中我如何获取tbl_attendance中user_id与application_status 3和4没有当前日期的所有用户
attendance_id user_id date_in attendance_status status 0=absent 1=present 3 = onleave 4 = onoff
1 1 2017-02-05 1
2 36 2017-02-11 4
3 36 2017-02-11 4
4 36 2017-02-11 3
5 1 2017-02-02 1
6 36 2017-02-01 1
我的代码就像这样
$date=date('Y-m-d');
$this->db->where('tbl_users.user_id NOT IN(SELECT user_id FROM tbl_attendance WHERE tbl_attendance.date_in= "'.$date.'" )');
$this->db->where_in( 'tbl_attendance.attendance_status', array( '3', '4' ) );
想要将这两行合并并产生输出,如果当前日期存在于3或4中请帮助我
答案 0 :(得分:0)
你可以尝试这样。结合两个条件
$this->db->where("tbl_users.user_id NOT IN(SELECT user_id FROM tbl_attendance WHERE tbl_attendance.date_in='$date' AND tbl_attendance.attendance_status IN(3,4))");
答案 1 :(得分:0)
看到您正在使用查询构建器...
$this->db->group_start()
$this->db->where_in( 'tbl_attendance.attendance_status', array( '3', '4' ) );
$this->db->where_not_in('tbl_users.user_id', 'SELECT user_id FROM tbl_attendance WHERE tbl_attendance.date_in = '. $date, false)
$this->db->group_end()
应该有效