尝试使用以下LEFT JOIN
解决问题但在此之后陷入困境
SELECT COUNTRY FROM VISIT LEFT JOIN S ON S.CRUISENUM=VISIT.CRUISENUM (SELECT SHIP.SHIPNUM , WEIGHT , CRUISENUM FROM CRUISE LEFT JOIN SHIP ON CRUISE.SHIPNUM = SHIP.SHIPNUM) AS S
答案 0 :(得分:0)
您可以在同一查询中进行两次连接,无需创建子查询。
SELECT V.COUNTRY, AVG(S.WEIGHT)
FROM visit V
LEFT JOIN cruise C ON ( C.CRUISENUM = V.CRUISENUM )
LEFT JOIN ship S ON ( S.SHIPNUM = C.SHIPNUM )
GROUP BY V.COUNTRY
答案 1 :(得分:0)
除非确实需要,否则请避免使用子查询。您通过JOIN进入了正确的解决方案。 (但是你不需要左连接,因为如果ship
记录不存在,那么你不想计算任何东西。)
SELECT COUNTRY, AVG(weight)
FROM VISIT
JOIN CRUISE USING (cruisenum)
JOIN SHIP USING (shipnum)
GROUP BY COUNTRY
答案 2 :(得分:0)
按总重量计算的最大构建者
select builder from ship where max(weight) in
(select SUM(WEIGHT) from ship group by builder)
列出至少访问过两个不同国家/地区的巡航主管的名字。我尝试过此代码,但它对我来说也不起作用
SELECT DISTINCT C1.DIRECTOR
FROM CRUISE C1 , CRUISE C2
WHERE C1.DIRECTOR =C2.DIRECTOR AND C1.SHIPNUM = C2.SHIPNUM