您现在的位置是:首页 > PHP学习

李清波 2021-06-21 PHP学习 1373 复制当前网址

Thinkphp使用having查询重复的数据

having方法只有一个参数,并且只能使用字符串

例如:

Db::table('score')
    ->field('username,max(score)')
    ->group('user_id')
    ->having('count(test_time)>3')
    ->select();

生成的SQL语句是:

SELECT username,max(score) FROM score GROUP BY user_id HAVING count(test_time)>3


一般having需要group配合同时使用

文章来源:https://www.liqingbo.com/blog-1766.html

评论