我有一个像这样的查询
SELECT class_id,student_id,title,location
FROM class AS c
INNER JOIN library AS l
ON (l.student_id = c.student_id)
group by class_id,student_id;
输出:
class_id student_id title location
1 mac smart 2ndfloor
1 john smart 2ndfloor
1 charles smart 2ndfloor
2 james hard 1stfloor
另一个查询
SELECT school_id,class_id,s.title FROM school
输出:
school_id class_id title
1 1 school1
1 1 school1
1 2 school1
我必须先显示学校记录,然后显示该学校的课程(即)
school_id class_id title
1 NULL school //here school title and id
1 1 2ndfloor //here classes in that school
2 NuLL school2 //here next school title and id
2 1 2ndfloor //here classes in the next school
我该如何实现这一点,请告诉我它可以在 mysql 本身中完成,或者我需要使用 java List iterator 来迭代它。我正在使用 mysql 数据库和 java。