这里有两个表。
Table1
SchoolID Teacher_name comm_yr
01 John 1990
02 Heley 1995
03 George 1994
04 Chris 1998
05 Mary 1993
Table2
School_ID Student_name
01 Heley
02 Chris
03 Chris
04 Mary
05 Heley
我想列出每个学生作为学生的年份和每个学生作为老师的年份。
SELECT Teacher_name, comm_yr As Teacher_comm_yr, comm_yr As Student_comm_yr
FROM Table1 INNER JOIN Table2
WHERE comm_yr (SELECT comm_yr As Teacher_comm_yr From Table1
Where teacher_name=student_name);
表显示
Teacher_name Teacher_comm_yr Student_comm_yr
John 1990 1990
Heley 1995 1995
George 1994 1994
Chris 1998 1998
Mary 1993 1993
但我想要的是
Teacher_name Teacher_comm_yr Student_comm_yr
John 1990
Heley 1995 1990
George 1994
Chris 1998 1995
Chris 1998 1994
Mary 1993 1998
但我只能在同一年执行你能帮忙吗..
谢谢!