Я уже пробовал Count, select, sum с группировкой, но мне все еще не удается достичь желаемого результата.
Я хочу получить название раздела, общее количество студентов и отдельное количество мужчин и женщин. Я хочу сделать это с помощью 1 запроса.
Желаемый результат:
Мужской
Женский
Section 1
10
Раздел 2
8
Схема таблицы:
- tbl_section:section_id, section_name
- tbl_student: stud_id,stud_name,gender,section_id(внешний ключ)
Код: Выделить всё
$total =$this->db
->selectCount('gender')
->from(tbl_student)
->join('tbl_section','tbl_student.section_id = tbl_section.section_id)
->where('tbl_student.gender = "male")
->get()
->result_array();
Код: Выделить всё
select section.section_name,count(stud_id)
from tbl_student
join section on tbl_student.section_id=section.section_id
where tbl_student.gender = "Male"
group by section.section_id;
Подробнее здесь: https://stackoverflow.com/questions/702 ... odeigniter
Мобильная версия