yii2 如何查询统计?
查询数据分组统计
推荐学习:yii框架
yii查询数据分组统计
$query=Information::find()->groupBy('insertion_time')->alias('a')->select('count(*) as total,a.*')->all();
本地正常,但放在线上就报错,所以就用原生SQL去查询
$sql = "SELECT count(*)as total,insertion_time FROM `tre_information_hints` GROUP BY insertion_time"; $query = Yii::$app->getDb()->createCommand($sql)->queryAll(); ------------------------------------------------------------------------------------------- select from_unixtime(created_at, '%Y-%m-%d') AS time,count(DISTINCT user_id) as mun from tre_mineral_log GROUP BY time ORDER BY time desc
total是自己定义的字段存放统计数目。
以上就是yii2 如何查询统计的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号