我如何调试SQL子查询问题

时间:2019-06-26 01:16:00

标签: sql subquery

不确定我在哪里偏离了路线。我需要从第三张表中提取颜色名称才能显示。不确定如何????

FROM CAR_SALES JOIN
     CAR_INVENTORY
     ON CAR_SALES.CAR_VIN = CAR_INVENTORY.CAR_VIN
WHERE CAR_CYLINDER = 6 AND
     CAR_AUTO_MANUAL = 'M',
     (SELECT COLOR_NAME AS EXTCOLOR
      FROM COLOR
      WHERE COLOR_ID = CAR_INVENTORY.CAR_EXT_COLOR_ID
            (SELECT COLOR_NAME AS INTCOLOR
             FROM COLOR
             WHERE COLOR_ID=CAR_EXT_COLOR_ID
            )
    );

1 个答案:

答案 0 :(得分:0)

您只需要对色表进行两次连接:

select 
    EXTCOLOR.COLOR_NAME AS EXTCOLOR,
    INTCOLOR.COLOR_NAME as INTCOLOR
FROM CAR_SALES 
JOIN CAR_INVENTORY ON CAR_SALES.CAR_VIN = CAR_INVENTORY.CAR_VIN
JOIN COLOR as EXTCOLOR on EXTCOLOR.COLOR_ID = CAR_INVENTORY.CAR_EXT_COLOR_ID
JOIN COLOR as INTCOLOR on INTCOLOR.COLOR_ID = CAR_INVENTORY.CAR_INT_COLOR_ID
WHERE CAR_CYLINDER = 6 AND CAR_AUTO_MANUAL = 'M'