2017-01-01 75 views
0

我是使用codeigniter查詢生成器類的初學者。我在使用查詢生成器類轉換此查詢時遇到了問題。Codeigniter查詢生成器類

SELECT tb_country.`countryName`, COUNT(tb_country.countryId) AS totalCustomer FROM tb_customer 
    JOIN tb_city ON tb_city.`cityId` = tb_customer.`cityId` 
    JOIN tb_state ON tb_state.`stateId` = tb_city.`stateId` 
    JOIN tb_country ON tb_country.`countryId` = tb_state.`countryId` 
GROUP BY tb_country.`countryName` 

任何答案將有助於我,在此先感謝!

回答

1
$this->db 
    ->select("tb_country.countryName, COUNT(tb_country.countryId) AS totalCustomer", false) 
    ->from('tb_customer') 
    ->join('tb_city', 'tb_city.cityId = tb_customer.cityId') 
    ->join('tb_state', 'tb_state.stateId = tb_city.stateId') 
    ->join('tb_country', 'tb_country.countryId = tb_state.countryId') 
    ->group_by('tb_country.countryName') 
    ->get() 
    ->result(); 
+0

select函數的第三個參數中'true'的含義是什麼? –

+0

對不起,應該是假的。它意味着codeigniter不保護select語句。它是必需的,因爲有複合選擇語句,即在我們的選擇count(),因此將第二個參數設置爲false – puncoz

+0

檢查一次是否有效,這些天我沒有使用codeigniter,所以我不知道。 – puncoz