Home  >  Article  >  Backend Development  >  关于TP对数据库某个字段分组统计解决方案

关于TP对数据库某个字段分组统计解决方案

WBOY
WBOYOriginal
2016-06-13 12:18:311780browse

关于TP对数据库某个字段分组统计
SQL语句
select count(*) as total, 字段1 from 表名1 where (条件1) and (条件2) ...  group by 字段1 ORDER BY total ASC
N个条件查与不查都有可能

求大神指点怎么用ThinkPHP写

------解决思路----------------------
$mdel->field("count(*) as total")->where($condition)->group(字段1)->order(total ASC)

$condition为条件数组

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