如何以我们在codeigniter中的模型中使用的形式编写我们在mysql中使用的普通查询有人可以帮助我。
$sql = "SELECT gender,
SUM(CASE WHEN Handedness = 'Left-handed' THEN 1 ELSE 0 END) left_handed,
SUM(CASE WHEN Handedness = 'Right-handed' THEN 1 ELSE 0 END) right_handed,
COUNT(*) total
FROM Table1
GROUP BY gender WITH ROLLUP";
$data = $this->db->query($sql)->result_array();
如何以我们在 codeigniter 中的模型中使用的形式编写它
$this->db->select('financial_year');
$this->db->from('historical_data');
$this->db->where("financial_year BETWEEN '$from' AND '$to'");
$this->db->group_by('financial_year');
$query = $this->db->get();
$result = $query->result();