参考链接:group by聚合分组后如何获取分组数据_group分组后返回全部数据_自己收藏学习的博客-CSDN博客
SELECT r.device_id, GROUP_CONCAT(r.user_id SEPARATOR ';') user_id from related as r
JOIN devices as d on d.id = r.device_id
#where d.group_id = 1
GROUP BY r.device_id
标签:GROUP,group,获取,分组,user,device,join,id From: https://www.cnblogs.com/gaosj20210301/p/17332451.html