如何从 table 获取值,其中值取决于另一个 table?

How to get values from a table where value depends on another table?

大家好,我正在使用 Oracle 10g 使用 Oracle 数据库。我有 2 tables 汽车和拥有。

Create Table Car(
"license" varchar(255) not null primary key,
"year" varchar(255),
"model" varchar(255)
);

我插入了这些值

insert into Car values('12-3000', '2012', 'Axio');
insert into Car values('11-3000', '2008', 'Corolla');
insert into Car values('12-4000', '2013', 'Axio');
insert into Car values('12-5000', '2013', 'Premio');
insert into Car values('11-5000', '2010', 'Nano');
insert into Car values('11-6000', '2011', 'Alto');
insert into Car values('12-6000', '2015', 'Nano Twist');

这是自己的 table

Create Table Owns (
"nid" varchar(20) not null,
"license" varchar(255),
primary key("nid", "license")
);

我也插入了这些值

insert into Owns values('123451', '11-3000');
insert into Owns values('123452', '12-4000');
insert into Owns values('123453', '12-5000');
insert into Owns values('123454', '11-5000');
insert into Owns values('123455', '11-6000');
insert into Owns values('123456', '12-6000');
insert into Owns values('123457', '12-3000');

现在我需要找到那些拥有 "Axio" 型号的人的国家 ID (nid)。 如何编写该查询? 可能是这种...

select "nid" from Owns where "license" = (select "license" from Car where "model" = 'Axio');

提前致谢。

试试这个,

select "nid" from Owns where "license" IN (select "license" from Car where "model" = 'Axio');

您也可以尝试使用联接...