1、GROUP_CONCAT()获取分组下的详细数据
String jpql = "SELECT \n" +
"GROUP_CONCAT(u.id_) Ids,\n" +
"FROM table_user u" +
"WHERE u.is_delete_ = 0 AND a.status_ = 1" +
"GROUP BY u.sex";
2、FIND_IN_SET()获取不属于某角色的用户(用户与角色多对多关系)
SELECT
u.id_,
GROUP_CONCAT( g.group_id_ )
FROM
smart_users u
LEFT JOIN smart_user_groups g ON u.id_ = g.user_id_
GROUP BY
g.user_id_
HAVING
FIND_IN_SET( 20, GROUP_CONCAT( g.group_id_ ) ) = 0
//查询角色Id不是“20”的用户,find_in_set是查询如果用户角色Id数组包含20,返回1,不包含20返回0