关于 SQL 语句的问题 [ 2.0 版本 ]
SELECT count(*) as count,DATE_FORMAT(add_time,'%Y-%m-%d') as time FROM `service_ask` WHERE (`add_time` > '2017-03-01 00:00:00') AND (`add_time` < '2019-03-14 00:00:00') GROUP BY DATE_FORMAT(add_time,'%Y-%m-%d') ORDER BY `add_time` DESC LIMIT 100;
我这个语句在 mysql 里面运行是没问题的,可以查出来数据,主要是 group by 分组的问题,但是在 yii 里面这样写,就不行了,这是怎么回事呢?谢谢大佬
$query->select('count(*) as count')
->limit($pageSize)
->offset(($page - 1) * $pageSize)
->groupBy("DATE_FORMAT(add_time,'%Y-%m-%d')");
$query->orderBy("add_time desc");
echo $query->createCommand()->getRawSql();die;
SELECT count(*) as count, DATE_FORMAT(add_time, `"%Y-%m-%d")` AS `time` FROM `service_ask` WHERE (`add_time` > '2017-03-01 00:00:00') AND (`add_time` < '2019-03-14 00:00:00') GROUP BY `time` ORDER BY `add_time` DESC LIMIT 100
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 'FROM `service_ask` WHERE (`add_time` > '2017-03-01 00:00:00') AND (`add_time` < ' at line 3
时间: 0.01s
最佳答案
其他 0 个回答
没有找到数据。
PHP学院的中学生
注册时间:2018-10-23
最后登录:2024-09-23
在线时长:168小时13分
最后登录:2024-09-23
在线时长:168小时13分
- 粉丝29
- 金钱4725
- 威望30
- 积分6705