根据表“P”及表“SPJ”及表“J”,查询同时使用零件“螺母”,“螺栓”的工程名称。
时间: 2023-11-05 21:36:14 浏览: 249
根据上述表格,可以使用以下SQL语句进行查询:
SELECT DISTINCT J.JNAME FROM
SPJ SPJ1, SPJ SPJ2, J
WHERE SPJ1.JNO = SPJ2.JNO
AND SPJ1.JNAME = '螺母'
AND SPJ2.JNAME = '螺栓'
AND SPJ1.SNO = SPJ2.SNO
AND SPJ2.JNO = J.JNO;
该查询将返回同时使用零件“螺母”和“螺栓”的工程名称。注意,这个查询不包括使用其他零件的情况,只针对“螺母”和“螺栓”这两种零件。
相关问题
针对供应管理数据库SPJ,进行各种嵌套与集合查询供应管理数据库SPJ模式: 供应商表S(SNO,SNAME,STAT,CITY) 零部件表P(PNO,PNAME,COLOR,WT) 工程项目表J(JNO,JNAME,CITY) 供应情况表SPJ(SNO,PNO,JNO,QTY):(7)查询使用了“S002”供应的“螺母”零件的工程信息; (8)查询使用了 “螺母”零件的工程信息及相应供应商信息; (9)查询给“长春一汽”项目供应零件的供应商信息和供应情况; (10)查询给“长春一汽”项目供应“螺母”零件最多的供应商信息和供应情况; (11)查询使用了“螺母”或“螺丝刀”零件的工程项目信息; (12)查询既使用了“螺母”又使用了“螺丝刀”零件的工程项目信息; (13)查询使用了“螺母”零件但没有使用“螺丝刀”零件的工程项目信息; (14)查询使用过所有供应商供应的零件的工程项目信息。
(7) SELECT JNO, JNAME, CITY FROM J WHERE JNO IN (SELECT JNO FROM SPJ WHERE PNO IN (SELECT PNO FROM P WHERE PNAME = '螺母') AND SNO = 'S002');
(8) SELECT DISTINCT J.JNO, J.JNAME, J.CITY, S.SNO, S.SNAME, S.STAT, S.CITY FROM J, S, SPJ WHERE J.JNO = SPJ.JNO AND S.SNO = SPJ.SNO AND SPJ.PNO IN (SELECT PNO FROM P WHERE PNAME = '螺母');
(9) SELECT DISTINCT S.SNO, S.SNAME, S.STAT, S.CITY, SPJ.QTY FROM S, SPJ WHERE S.SNO = SPJ.SNO AND SPJ.JNO = (SELECT JNO FROM J WHERE JNAME = '长春一汽');
(10) SELECT TOP 1 S.SNO, S.SNAME, S.STAT, S.CITY, SPJ.QTY FROM S, SPJ WHERE S.SNO = SPJ.SNO AND SPJ.JNO = (SELECT JNO FROM J WHERE JNAME = '长
针对供应管理数据库SPJ,进行各种嵌套与集合查询供应管理数据库SPJ模式: 供应商表S(SNO,SNAME,STAT,CITY) 零部件表P(PNO,PNAME,COLOR,WT) 工程项目表J(JNO,JNAME,CITY) 供应情况表SPJ(SNO,PNO,JNO,QTY):(10)查询给“长春一汽”项目供应“螺母”零件最多的供应商信息和供应情况; (11)查询使用了“螺母”或“螺丝刀”零件的工程项目信息; (12)查询既使用了“螺母”又使用了“螺丝刀”零件的工程项目信息; (13)查询使用了“螺母”零件但没有使用“螺丝刀”零件的工程项目信息; (14)查询使用过所有供应商供应的零件的工程项目信息。
(10) SELECT TOP 1 S.SNO, S.SNAME, S.STAT, S.CITY, SPJ.QTY FROM S, SPJ WHERE S.SNO = SPJ.SNO AND SPJ.JNO = (SELECT JNO FROM J WHERE JNAME = '长春一汽') AND SPJ.PNO = (SELECT PNO FROM P WHERE PNAME = '螺母') ORDER BY SPJ.QTY DESC;
(11) SELECT DISTINCT J.JNO, J.JNAME, J.CITY FROM J, SPJ WHERE J.JNO = SPJ.JNO AND SPJ.PNO IN (SELECT PNO FROM P WHERE PNAME IN ('螺母', '螺丝刀'));
(12) SELECT DISTINCT J.JNO, J.JNAME, J.CITY FROM J, SPJ AS S1, SPJ AS S2 WHERE J.JNO = S1.JNO AND S1.JNO = S2.JNO AND S1.PNO = '螺母' AND S2.PNO = '螺丝刀';
(13) SELECT DISTINCT J.JNO, J.JNAME, J.CITY FROM J, SPJ AS S1 WHERE J.JNO = S1.JNO AND S1.PNO = '螺母' AND J.JNO NOT IN (SELECT JNO FROM SPJ WHERE PNO = '螺丝刀');
(14) SELECT J.JNO, J.JNAME, J.CITY FROM J WHERE NOT EXISTS (SELECT S.SNO FROM S WHERE NOT EXISTS (SELECT P.PNO FROM P WHERE P.PNO = SPJ.PNO AND SPJ.SNO = S.SNO AND SPJ.JNO = J.JNO));
阅读全文