Home  >  Article  >  PHP Framework  >  How to query statistics in yii2

How to query statistics in yii2

藏色散人
藏色散人Original
2020-01-09 10:05:333996browse

How to query statistics in yii2

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn