🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## GROUP分组查询和Having子句 有时候我们要进行分组查询,如以下SQL: ``` SELECT * FROM `user` WHERE `id` IN(1637, 1639, 1640 ) GROUP BY name ``` 在BeetlSql中直接拼条件调用group方法,传入字段即可: ``` Query<User> query = sqlManager.query(User.class); List<User> list = query .andIn("id", Arrays.asList(1637, 1639, 1640)) .groupBy("name") .select(); ``` 在分组查询之后,我们可能还要进行having筛选,只需要在后面调用having方法,传入条件即可。 ``` SELECT * FROM `user` WHERE `id` IN( 1637, 1639, 1640 ) GROUP BY name HAVING `create_time` IS NOT NULL ``` ``` Query<User> query = sqlManager.query(User.class); List<User> list = query .andIn("id", Arrays.asList(1637, 1639, 1640)) .groupBy("name") .having(query.condition().andIsNotNull("create_time")) .select(); ```