没有子查询的sql查询

时间:2012-03-22 23:22:51

标签: mysql sql

我需要重写这个查询,我不允许使用子查询。我需要选择比车轮重的部件的名称和颜色。

SELECT name, color
FROM parts
WHERE weight > (SELECT weight FROM parts WHERE name="wheel");

这是表格:

PARTS

ID    NAME    COLOR     WEIGHT    
1     wheel   black     100
2     tire    black     50
3     gear    red       20

提前致谢

3 个答案:

答案 0 :(得分:2)

加入自己

SELECT parts_a.name, parts_a.color 
FROM parts parts_a, parts parts_b
WHERE parts_a.weight > parts_b.weight
   AND parts_b.name = "wheel"

答案 1 :(得分:0)

你可以加入。

SELECT a.name, a.color 
FROM parts as a left join parts as b on a.ID=b.ID
WHERE a.weight > b.weight
AND b.name = "wheel"

答案 2 :(得分:-1)

我应该在不使用子查询的情况下写下此查询 SELECT C.pid 来自目录C,供应商S. WHERE S.sname ='Yosemite Sham'和C.sid = S.sid ANDC.cost≥ALL(选择C2.cost 来自目录C2,供应商S2  WHES S2.sname ='Yosemite Sham'和C2.sid = S2.sid)