2017-01-07 7 views
1

こんにちは、以下は、異なるテーブルからの異なるデータの数を取得するためのクエリです。単一のクエリを実行しているのcodeigniterでネストされたクエリを構築するには?

用途データベースヒットを最小限に抑えるために..です

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 

は、今私はCodeIgniterのビルダークラスの助けを借りて、CodeIgniterでは、この単一のクエリを構築したいので、誰かが私にしてください導くことができます。

ありがとうございます。この

$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 ... 

ようget_compiled_select をそして他人のために使用します。

答えて

2

あなたは使用することができます。

関連する問題