yii2学习笔记 ---查询数据分组统计

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)