好的,我有两个叫汽车和保险的桌子
汽车桌子的外观如下:
保险表类似于:
类型
引用编号
被保险人的表是这样的(首先是空的):
品牌
颜色
目标是将所有带保险的汽车导入被保险人表。
到目前为止,我所能想到的是:
"SELECT cars.reference_number, insured.reference_number FROM INSPECTIONS LEFT JOIN insured ON cars.reference_number = cars.reference_number ORDER BY cars.reference_number")
答案 0 :(得分:1)
根据您的解释(“所有带保险的汽车”)-被保险人也有reference_number,对吧?:
insert into insured (reference_number, brand, colour)
SELECT reference_number, brand, colour
FROM Cars
where reference_number in (select reference_number from insurance)
ORDER BY reference_number