# 聚合查询 在模型中可以调用数据库的聚合方法查询 ## count ```php User::where('status','>',0)->count(); ``` 转化为 SQL 为 ```sql SELECT COUNT(*) AS tp_count FROM `zh_user` WHERE `status` > 0 LIMIT 1 ``` ## avg ```php User::where('status',1)->avg('score'); ``` 转化为 SQL 为 ```sql SELECT AVG(`score`) AS tp_avg FROM `zh_user` WHERE `status` = 1 LIMIT 1 ``` ## max && min ```php User::max('id'); User::min('id'); ``` 转化为 SQL 为 ```sql SELECT MIN(`id`) AS tp_min FROM `zh_user` LIMIT 1 SELECT MAX(`id`) AS tp_max FROM `zh_user` LIMIT 1 ```