Usage of FIND_IN_SET in query [closed]

2019-08-18 00:06发布

问题:

  $query=$this->db
->select(a.date,group_concat(s.name)
->from("tbl_attendance a,tbl_students s") 
->WHERE ("FIND_IN_SET(s.student_id, a.attendance)")->group_by("a.date")
->get();

I wanted to know whether I have used the FIND_IN_SET and group_by functions correctly. Thanks in advance

回答1:

FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings

so you should search if a value is != 0

eg:

->where("FIND_IN_SET(s.student_id, a.attendance) !=", 0)
->group_by("a.date")