yii2 How to query statistics?
Query data grouping statistics
Recommended learning: yii framework
yii query data grouping statistics
$query=Information::find()->groupBy('insertion_time')->alias('a')->select('count(*) as total,a.*')->all();
is normal locally, but an error is reported when placed online, so I use native SQL to query
$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 is a self-defined field to store the statistical number.
The above is the detailed content of How to query statistics in yii2. For more information, please follow other related articles on the PHP Chinese website!