当student表中type=1时,关联teacher表展示老师的名字,
当student表中type=2时,关联course表展示课程的名字的名字,
sql语句:
SELECT s.*,
CASE WHEN s.type=1 THEN(SELECT t.c_name from teacher t WHERE t.c_id=s.theam)
WHEN s.type=2 THEN(SELECT d.dname from course d WHERE d.deptno=s.theam)END ‘resu’
from student s
Java类的映射:
查询结果:
[Student{id=1, type=‘1’, theam=‘1’}StudentVo{val=‘lily’}, Student{id=2, type=‘2’, theam=‘2’}StudentVo{val=‘c++’}]