Split mysql column in codeigniter
the above link is one of my question. I got the answer for the above question. But now I have a sql query as follows,
SELECT SUM(IF(pay_type = 1, `pay_amount`, `0))` mess_pay, SUM(IF(pay_type=2, `pay_amount`, `0))` est_pay FROM (`mess_stock`);
I want to use above code in codeigniter.
I have tried the following method
$this->db->select('SUM(IF(pay_type = 1, pay_amount, 0)) mess_pay, SUM(IF(pay_type=2, pay_amount, 0)) est_pay');
$this->db->from('mess_stock');
But it throws the following output
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mess_pay, SUM(IF(pay_type=2, `pay_amount`, `0))` est_pay FROM (`mess_stock`)' at line 1
SELECT SUM(IF(pay_type = 1, `pay_amount`, `0))` mess_pay, SUM(IF(pay_type=2, `pay_amount`, `0))` est_pay FROM (`mess_stock`)
Filename: /var/www/college/modules/mess_fees/models/mess_fees_model.php
Line Number: 25
How can I execute the above query?