ThinkPHP 5.0 ORM查询问题

想查询一个模型中 某个字段有多少条相同的记录,该怎么查
https://img2.mukewang.com/5c8f66c40001b6fd01380166.jpg 例如:查询表中 id 为 1的有多少条

用select() 查再 count(array) 应该是太浪费资源了吧

holdtom
浏览 548回答 3
3回答

慕丝7291255

select *,count(*) from t_table group by id tp5官方手册写法 Db::table('think_user') ->field('user_id,username,max(score)') ->group('user_id') ->select(); 生成的SQL语句是: SELECT user_id,username,max(score) FROM think_score GROUP BY user_id

慕仙森

thinkphp有count()方法啊。。。。 ->where('id = 1')->count();

红颜莎娜

直接count(1) where id = 1
打开App,查看更多内容
随时随地看视频慕课网APP