2
回答
PHP SQL查询报错
【腾讯云】学生服务器套餐10元/月 >>>   

代码如下:用上面注释掉的SQL没问题,用下面的SQL执行。报截图中的错误,但是打印的SQL在MySQL中却能执行。求解!

public function getCount()
    {
//        $hql = "SELECT DATE_FORMAT(a.createtime,'%Y') FROM " . self::getClassName() . " a GROUP BY DATE_FORMAT(a.createtime,'%Y')";
        $hql = " SELECT DATE_FORMAT(a.createtime, '%Y'), " .
            "SUM(CASE WHEN a.flag = 0 OR a.flag = 1 OR a.flag = 4 OR a.flag = 7 OR a.flag = 8 OR a.flag = 13 THEN 1 ELSE 0 END) " .
            "AS 'num',SUM(CASE WHEN a.flag = 9 OR a.flag = 10 THEN 1 ELSE 0 END) AS 'call_num', " .
            "SUM(CASE WHEN a.flag = 2 OR a.flag = 3 OR a.flag = 5 OR a.flag = 11 OR a.flag = 12 THEN 1 ELSE 0 END) " .
            "AS 'early_num' FROM " . self::getClassName() ." a GROUP BY DATE_FORMAT(a.createtime, '%Y')";
//        var_dump($hql);
//        die;
        return $this->getModelsManager()->createQuery($hql)->execute();
    }

举报
顶部