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

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

WBOY
Release: 2016-06-13 12:18:31
Original
1829 people have browsed it

关于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为条件数组

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