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中文網其他相關文章!