codeigniter查询问题

时间:2013-01-10 09:07:28

标签: mysql codeigniter activerecord

我有这个问题:

$this->db->select('COUNT(tran_ID) AS count, CASE WHEN MONTH(days)>=4 THEN concat(YEAR(days), "-", YEAR(days)+1) ELSE concat(YEAR(days)-1, "-", YEAR(days)) END AS format_date,product_class AS saleCol');

我在

上遇到语法错误
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 'WHEN MONTH(days)>=4 THEN concat(YEAR(days), `"-"`, YEAR(days)+1) ELSE concat(YEA' at line 1

SELECT COUNT(tran_ID) AS count, `CASE` WHEN MONTH(days)>=4 THEN concat(YEAR(days), `"-"`, YEAR(days)+1) ELSE concat(YEAR(days)-1, `"-"`, YEAR(days)) END AS format_date, `product_class` AS saleCol FROM (`transactions`) WHERE `trans_type` = 'E' AND `product_class` != '0' GROUP BY `format_date`, `product_class`

1 个答案:

答案 0 :(得分:1)

尝试此查询,将FALSE添加为select语句

中的第二个参数
$this->db->select(
                  'COUNT(tran_ID) AS count, 
                   CASE WHEN MONTH(days)>=4 THEN concat(YEAR(days), "-", YEAR(days)+1)
                     ELSE concat(YEAR(days)-1, "-", YEAR(days)) 
                   END AS format_date,
                   product_class AS saleCol',FALSE);