0
SELECT
Student.id,
Student.first_name,
Student.last_name,
count(`Attendance`.`id`) as total
FROM `karate`.`attendances` AS `Attendance`
RIGHT JOIN `karate`.`students` AS `Student` ON (`Attendance`.`student_id` = `Student`.`id`)
WHERE 1
AND `Attendance`.`attendance_date` BETWEEN '2012-07-01' AND '2012-07-31'
AND (Student.active = '1')
AND (Student.type = 'student')
GROUP BY `Student`.`id`
ORDER BY total ASC
주어진 날짜 범위 내에서 전체 참석자 수를 원하지만 참석 한 학생의 기록이 두 개만 표시됩니다. 그러나 날짜 확인 조건을 삭제하면 정상적으로 작동합니다. 그것은 바로 가입 된 행에 대한 attendance_date
때문에 NULL의 값이의 사전오른쪽 결합이 작동하지 않습니다.
그러나 이것은 여전히 참석 학생을 보여주는 작동하지 않습니다 (:? –
당신이 당신의 원래의 질문으로 업데이트 쿼리를 게시 할 수 있습니다 –
SELECT Student.id, 학생 당신은 당신의 상태에서이 사건을 포함해야 .first_name, student.last_name, 총계에서 (공석'.'id') 총계로'공수'.'학생'학생'우연한'공수.'태도'출석'(출석. 'student_id' ='Student'.'id') WHERE 1 AND ('Attendance'.attendance_date'는 NULL이거나'Attendance'.attendance_date''BETWEEN '2012-07-01'AND '2012-07-31') AND (Student.active = '1') AND (Student.type = 'student') GROUP BY'Student'.id' 주문 합계 ASC –