企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
* [ ] 功能 * 用于配合 group 方法完成从分组的结果中筛选(通常是聚合条件)数据 * having方法有两个参数:$data 和 $andor * $data 是聚合条件,支持数据、字符串 * 当 $data 为数组的时候,$andor 条件组合类型设置才有效,or 或 and,默认 and * 当 $data 为字符串的时候,$andor 设置值无效 * 场景:user 数据库的 user_account 表只有 3 条数据,数据为: user_account 表 | uid | username | score | | :---: | :---: | :--: | | 1 | 张三 | 100 | | 2 | 李四 | 97 | | 3 | 隔壁老王 | 100 | * 用法一:数组方式 ~~~ // 过滤字段 $field = 'uid,username,count(score) as count_score'; // 数组聚合条件 $having = array( 'count_score[>]' => 99, 'uid[>]' => 1, ); // 按照用户 ID 分组 $group = 'uid'; // 条件组合关系,默认是 and $andor = 'and'; $data = mysql\User::table('account')->field( $field )->having( $having, $andor )->group( $group )->select(); ~~~ 查询结果: ~~~ array( array( 'uid' => 3, 'username' => '隔壁老王', 'count_score' => 100, ), ); ~~~ * 用法二:字符方式 ~~~ // 过滤字段 $field = 'uid,username,count(score) as count_score'; // 字符聚合条件 $having = 'count_score > 99 and uid > 1'; // 按照用户 ID 分组 $group = 'uid'; $data = mysql\User::table('account')->field( $field )->having( $having )->group( $group )->select(); ~~~ 查询结果: ~~~ array( array( 'uid' => 3, 'username' => '隔壁老王', 'count_score' => 100, ), ); ~~~