为了账号安全,请及时绑定邮箱和手机立即绑定

ThinkPHP 5.0 ORM查询问题

ThinkPHP 5.0 ORM查询问题

PHP
holdtom 2019-03-10 17:54:25
想查询一个模型中 某个字段有多少条相同的记录,该怎么查 例如:查询表中 id 为 1的有多少条 用select() 查再 count(array) 应该是太浪费资源了吧
查看完整描述

3 回答

?
慕丝7291255

TA贡献1859条经验 获得超6个赞


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
查看完整回答
反对 回复 2019-03-18
?
慕仙森

TA贡献1827条经验 获得超8个赞

thinkphp有count()方法啊。。。。

->where('id = 1')->count();
查看完整回答
反对 回复 2019-03-18
?
红颜莎娜

TA贡献1842条经验 获得超12个赞

直接count(1) where id = 1

查看完整回答
反对 回复 2019-03-18
  • 3 回答
  • 0 关注
  • 547 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信