2017-01-01 94 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