У меня есть такой запрос:
$this->db->query("SELECT `no_request`,`date_in`,`location`,`d_point`,`username`,SUM(request.`persen`) AS 'Persen',
CASE
WHEN SUM(Persen) = 0 THEN 'Pending'
WHEN SUM(persen) = 100 THEN 'Complete'
WHEN SUM(persen) > 0 AND SUM(persen) < 100 THEN 'On Process'
END AS 'states'
FROM request WHERE `location` = '$lokasi' GROUP BY `no_request`
HAVING
CASE
WHEN `Persen` = 0 THEN `states` = 'Pending'
END", TRUE)->result_array();
Я хочу сделать запрос оригинальным из codeigniter, но у меня возникла проблема с моим запросом:
$this->db->select($this->fetching_column);
$this->db->select_sum($this->persen);
$this->db->select("
CASE
WHEN SUM('persen') = 0 THEN 'Pending'
WHEN SUM('persen') = 100 THEN 'Complete'
WHEN SUM('persen') > 0 SUM('persen') < 100 THEN 'On Process'
END", FALSE);
$this->db->from($this->table);
$this->db->where($this->location . ' = ' . $location);
$this->db->group_by($this->group);
$result = $this->db->get();
Мой запрос неверный? или я не могу использовать case
внутри $this->db->select()