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

How to query statistics in yii2

藏色散人
Release: 2020-01-09 10:05:33
Original
4012 people have browsed it

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();
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template