Вот мой вопрос SQL ...
У меня есть три таблицы:
course_subcategory
-------------------------------------------------------
| course_subcat_id | course_cat_id| subcoursename| code|
-------------------------------------------------------
course_category
-------------------------------------------------------
| course_cat_id | coursename| code| project |deleted|
-------------------------------------------------------
events
------------------------------------------------------------------------------
|event_id|title| project |course_cat_id |course_subcat_id|no_of_house_surveyed
-----------------------------------------------------------------------------
-
Я хочу показать общее количество обследованных домов и количество событий, произошедших с одинаковыми course_cat_id и course_subcat_id.
Вот мой код.
модели
function getCourseCat(){
$this->db->select('COUNT(e.title) as no_of_events, SUM(e.no_of_house_surveyed) as total_house_surveyed, c.course_cat_id, c.coursename,s.course_subcat_id,
s.subcoursename' )
->from('events e')
->join('course_category c ON e.course_cat_id = c.course_cat_id')
->join('course_subcategory s ON e.course_subcat_id = s.course_subcat_id')
->group_by('e.event_id');
$result=$this->db->get()->result();
}
контроллер
$ data ['course_cat'] = $ this-> test_event_summary_model-> getCourseCat ();enter code here
просмотров
foreach($course_cat->result() as $c){
if ($c->no_of_events == 0) {
continue;
}
echo "<td>".$c->no_of_events."</td>";
$total_events += $c->no_of_events;
}