今天遇到一个问题,消息通知可以同时发送给多个班级,而查询消息通知的时候并不需要根据班级分组,如何把多个班级的名称合并成一行数据追加到消息通知的后面呢
然后就发现了 group_concat:
SELECT cni.ID, cni.Contents, cni.LookCount, cni.CreateDate, GROUP_CONCAT(ci.`Name`) AS ClassName, ci.TName FROM td_classnoticeinfo AS cni INNER JOIN td_classnoticemapping AS cnm ON cnm.NoticeID = cni.ID INNER JOIN td_classinfo AS ci ON cnm.ClassID = ci.ID WHERE ci.UserID=1 GROUP BY cni.ID, cni.Contents, cni.LookCount, cni.CreateDate, ci.TName
结果就是这样了
1 test data!!! 0 2017-10-10 00:00:00 小太阳班,小山羊班 邢帅杰
参考:https://www.cnblogs.com/thomas12112406/p/5813394.html