关于在SQL中连接表 [英] Regarding joining tables in SQL
本文介绍了关于在SQL中连接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在加入两张桌子时遇到了麻烦。我想选择仅具有1998年特定年份的AID,价格和bname,属于欧米茄
I am having troubles joining two tables. I want to select AID, price and bname that have a specific year 1998 only and belong to omega
select AID, price, bname
from a, b
where ........
可以给出什么条件?
what condition can be given?
create table a
(AID number,
price number
year number,
pk (AID));
create table b
(BID number,
bname char,
pk(BID));
create table c
(AID number
BID number
pk(AID,BID)
fk (AID) references a(AID),
fk (BID) references b(BID));
insert into a values (1, 250, 1990);
insert into a values (2, 150, 1998);
insert into b values (1001, 'omega');
insert into b values (1002, 'sharp');
insert into c values (1, 1001);
insert into c values (2, 1002);
推荐答案
这与你之前的问题非常相似,但无论如何...
考虑以下
This is awfully similar to your previous question but anyhow...
Consider the following
select a.aid, a.price, b.bname
from a inner join c on a.AID = c.AID
inner join b on c.BID = b.BID
where b.name = 'omega'
and a.year = 1998;
I would suggest going through Join Fundamentals[^] and similar tutorials.
尝试:
Try:
SELECT a.AID, a.Price, b.bName FROM a
JOIN c ON c.AID = a.AID
JOIN b ON c.BID = b.BID
WHERE b.bname = 'omega' AND a.year = 1998
但是...你的样本数据赢了;得到任何结果,因为没有这样的信息!
如果你改变了一年到1990年,或bname为sharp然后它将。
But...your sample data won;t give any results, because there is no such information!
If you change the year to 1990, or the bname to "sharp" then it will.
这篇关于关于在SQL中连接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文