(参考群体功能) -
SELECT `subject`,
GROUP_CONCAT(`student_id` SEPARATOR ',') as sid,
(SELECT concat(fname,' ',surname )
FROM student_registration
WHERE student_id IN (sid) ) as name
FROM `email` GROUP BY `subject`
答案 0 :(得分:0)
尝试一下,如果你想要别的东西还原它 -
SELECT a.`subject`, GROUP_CONCAT(a.student_id SEPARATOR ',') AS sid, CONCAT( b.fname,' ',b.surname ) AS 'name'
FROM email AS a
LEFT JOIN student_registration AS b ON b.student_id=a.student_id
GROUP BY a.`subject`;