您可以通过一个查询来执行此操作,使用left outer join
and coalesce
(如果我的逻辑正确):
SELECT Striker_Name, Team_Name, coalesce(MO.STARTYEAR, g.start_year), MO.ENDYEAR
FROM (SELECT NAME AS Striker_Name, MID
FROM MEMBER
) ME JOIN
(SELECT MID, TID, STARTYEAR AS Start_Year, ENDYEAR AS End_Year
FROM MEMBEROF
WHERE POSITION = 'striker'
) MO ON ME.MID = MO.MID left outer JOIN
(SELECT NAME AS Team_Name, TID
FROM TEAM
) T
ON MO.TID = T.TID left outer JOIN
(SELECT GID, MIN(GAME.YEAR) AS Start_Year FROM GAME GROUP BY TID
) G
ON G.TID = MO.TID
ORDER BY Striker_Name, Start_Year
您似乎从最早的游戏开始填写开始年份。只需进行连接并决定使用select
哪一个。