数据库查询 字段`的问题 [ 2.0 版本 ]
今天做到数据统计,不想用拼接sql,用模型来查遇到了个问题
查询1分钟内访问大于60的数据:
$q1 = Weblogs::find()
->where(['website'=>$domain])
->andWhere(['between','`time`',$stime,$etime])
->groupBy("`ip`,DATE_FORMAT(`time`,'%Y-%m-%d %H:%i')")
->select("count(ip) as num,ip,DATE_FORMAT(`time`,'%Y-%m-%d %H:%i') as time");
$query = new Query();
$list = $query->select('*')->from(['t1' => $q1])->where('num > 60')->createCommand()->queryAll();
结果数据库报错:sql为:
SELECT * FROM (SELECT count(ip) AS num
, ip
, DATE_FORMAT(time
, '%Y-%m-%d %H:%i')
AS time
FROM rf_weblogs
WHERE (website
='www.inihouse.com') AND (time
BETWEEN '2019-07-18 00:00:00' AND '2019-07-18 23:59:59') GROUP BY ip
, DATE_FORMAT(time
, '%Y-%m-%d %H:%i')
) t1
WHERE num > 60
在 DATE_FORMAT(time
, '%Y-%m-%d %H:%i')
中多了一对 `` 这怎么处理
nswindlights 补充于 2019-07-18 15:05
nswindlights 补充于 2019-07-18 15:13
解决了,传数组就可以了
$q1 = Weblogs::find()
->where(['website'=>$domain])
->andWhere(['between','`time`',$stime,$etime])
->groupBy(['ip',"DATE_FORMAT(`time`,'%Y-%m-%d %H:%i')"])
->select(['count(ip) as num','ip',"DATE_FORMAT(`time`,'%Y-%m-%d %H:%i')"]);
$query = new Query();
$list = $query->select('*')->from(['t1' => $q1])->where('num > 60')->createCommand()->queryAll();
共 0 个回答
没有找到数据。
nswindlights 江苏太仓
注册时间:2014-09-18
最后登录:2020-03-30
在线时长:74小时58分
最后登录:2020-03-30
在线时长:74小时58分
- 粉丝5
- 金钱986
- 威望80
- 积分2526