嗨下面是查询,以从不同的表,在不同的数据计数。
select(
select count(*)
from teachers
where teacher_status = 1
)as teacher_count,
(
select count(*)
from students
where student_status = 1
)as students_count,
(
select count(*)
from housekeepers
where housekeeper_status = 1
)as housekeeping_count,
(
select count(*)
from students
where student_status = 1 and
gender = "Male"
) as total_male_student_count,
(
select count(*)
from students
where student_status = 1 and
gender = "Female"
) as total_female_student_count
现在我想建立与笨生成器类的帮助下笨这种单一的查询,这样可以有人指导我请..
运行单个查询的目的是尽量减少数据库命中。
提前致谢..!!!
你可以使用:get_compiled_select
这样
$this->db->select('count(*) as count');
$this->db->from('teacher_status');
$teacher_status = $this->db->get_compiled_select();
$this->db->select("select($teacher_status)as teacher_count, ... ");
this->db ...
和他人使用。