我有这个查询:

$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`

最佳答案

尝试此查询,在选择语句中添加FALSE作为第二个参数

$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);

关于mysql - Codeigniter查询问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14254188/

10-13 08:10