6.设有一个SPJ数据库,包括s、P、J、SPJ四个关系模式: S(SNO,SNAME,STATUS,CITY); P(PNO,PNAME,COLDR,WEIGHT); J(JNO,JNAME,CITY); SPJ(SNO,PNO,JNO,QTY); 供应商表S由供应商代码(SNO)、供应商姓名(SNAME)、供应商状态(STATUS)、供应商所在城市(CITY)组成; 零件表P由零件代码(PNO)、零件名(PNAME)、颜色(COLOR)、质量(WEIGHT)组成; 工程项目表J由工程项目代码(JNO)、工程项目名(JNAME)、工程项目所在城市(CITY)组成; 供应情况表SPJ由供应商代码(SNO)、零件代码(PNO)、工程项目代码(JNO)、供应数量(QTY)组成,表示某供应商供应某种零件给某工程项目的数量为QTY。 今有若干数据如下: 试分别用关系代数、ALPHA语言、QBE语言完成下列操作:
(1) 求供应工程J1零件的供应商号码SNO:
关系代数表示:π_SNO(σ_JNO='J1'(SPJ))
ALPHA语言表示:SELECT SNO FROM SPJ WHERE JNO = 'J1'
QBE语言表示:[Suppliers].[SNO] = SPJ.SNO AND SPJ.JNO = 'J1'
(2) 求供应工程J1零件P1的供应商号码SNO:
关系代数表示:π_SNO(σ_JNO='J1'^_PNO='P1'(SPJ))
ALPHA语言表示:SELECT SNO FROM SPJ WHERE JNO = 'J1' AND PNO = 'P1'
QBE语言表示:[Suppliers].[SNO] = SPJ.SNO AND SPJ.JNO = 'J1' AND SPJ.PNO = 'P1'
(3) 求供应工程J1零件为红色的供应商号码SNO:
关系代数表示:π_SNO(σ_COLOR='红色'(σ_JNO='J1'(SPJ)⨝P))
ALPHA语言表示:SELECT SNO FROM SPJ, P WHERE SPJ.JNO = 'J1' AND SPJ.PNO = P.PNO AND P.COLOR = '红色'
QBE语言表示:[Suppliers].[SNO] = SPJ.SNO AND SPJ.JNO = 'J1' AND [Parts].[PNO] = SPJ.PNO AND [Parts].[COLOR] = '红色'
(4) 求没有使用天津供应商生产的红色零件的工程号JNO:
关系代数表示:π_JNO(σ_COLOR='红色'(σ_CITY≠'天津'(SPJ)⨝P))
ALPHA语言表示:SELECT JNO FROM SPJ, P WHERE SPJ.PNO = P.PNO AND P.COLOR = '红色' AND NOT EXISTS (SELECT * FROM Suppliers WHERE Suppliers.SNO = SPJ.SNO AND Suppliers.CITY = '天津')
QBE语言表示:[Projects].[JNO] = SPJ.JNO AND [Parts].[PNO] = SPJ.PNO AND [Parts].[COLOR] = '红色' AND NOT EXISTS (SELECT * FROM Suppliers WHERE Suppliers.SNO = SPJ.SNO AND Suppliers.CITY = '天津')
(5) 求至少用了供应商Sl所供应的全部零件的工程号JNO:
关系代数表示:π_JNO(σ_PNO∈{π_PNO(σ_SNO='Sl'(SPJ))}(SPJ))
ALPHA语言表示:SELECT JNO FROM SPJ WHERE PNO IN (SELECT PNO FROM SPJ WHERE SNO = 'Sl')
QBE语言表示:[Projects].[JNO] = SPJ.JNO AND SPJ.PNO IN (SELECT PNO FROM SPJ WHERE SNO = 'Sl')
标签:p70,--,SNO,J1,SPJ,PNO,数据库系统,JNO,SELECT
From: https://www.cnblogs.com/whwh/p/18140066