There are three tables which are like this:
(有三个表,如下所示:)
S (sid, sname, scity)
P (pid, pname, color, weight)
SP (sid, pid, quantity)
The question is to return those sname(s) which has(have) all of the pid(s) with blue color
(问题是返回具有所有蓝色的pid的那些sname)
At first I wrote this one:
(首先,我写了这个:)
SELECT S.sname FROM S INNER JOIN SP ON S.sid = SP.sid
INNER JOIN P ON SP.pid = P.pid
WHERE color = 'blue';
which of course is not right, because it returns those sname(s), even it has just one P with blue color.
(当然这是不对的,因为即使它只有一个带有蓝色的P,它也会返回这些sname。)
My second query is this one:
(我的第二个查询是这个:)
SELECT S.sname FROM S INNER JOIN SP ON S.snum = SP.snum
INNER JOIN P ON SP.pnum = P.pnum
WHERE SP.pnum IN
(SELECT pnum FROM P WHERE color != 'blue');
This is also not right, because it seems that IN
operator acts like multiple OR
conditions.
(这也不对,因为看起来IN
运算符的行为类似于多个OR
条件。)
Would you please let me know how can I set a condition which instead of OR
, acts like AND
? (您能否让我知道如何设置一个条件,该条件代替OR
而是像AND
?)
ask by drdn translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…