Introduction to Database Systems (fifth edition) Query Problem Solution

- at least with the engineering requirements No. Supplier S1 supplied all parts JNO
SELECT SNO the DISTINCT
the FROM SPJ
the WHERE SNO the NOT the IN (
the SELECT SPJ.SNO
the FROM SPJ, P, S
the WHERE SPJ.PNO = P.PNO the AND SPJ.SNO = s.SNO AND P.COLOR = 'red' AND S.CITY = 'Tianjin'
)

- seeking supply part projects J1 red supplier number SNO
SELECT SNO the DISTINCT
from SPJ, P
WHERE JNO = 'J1'and SPJ.PNO the IN (
SELECT PNO the DISTINCT
the FROM P
the WHERE COLOR =' red '
)

- seeking supply project J1 P1 parts supplier number SNO
the SELECT DISTINCT SNO
from SPJ
the WHERE JNO = 'J1' and PNO = 'P1'

- seeking supply project J1 parts supplier number SNO
the SELECT DISTINCT SNO
from SPJ
the WHERE JNO = 'J1'

- identify the name and city all suppliers:
the SELECT SNAME, the CITY
from S

- find the names of all parts, color, weight
SELECT PNAME, COLOR, WEIGTH
from P

- to find out using vendor supplied parts s1 Construction number
SELECT the DISTINCT JNO
the FROM SPJ
the WHERE SNO = 'Sl'

- find out the name and number of the various parts of the project J2 use
the SELECT P.PNAME, QTY
the FROM SPJ, P
the WHERE SPJ.PNO = P.PNO the AND JNO = 'J2'

- identify all part numbers Shanghai manufacturers supply
the SELECT DISTINCT PNO
the FROM SPJ
the WHERE SPJ.SNO the IN (
the SELECT SNO
the FROM S
the WHERE the CITY = 'Shanghai'
)

- to find the parts produced using the Shanghai project name
the SELECT DISTINCT J.JNAME
the FROM J, S, SPJ
the WHERE SPJ.SNO = s.sno the AND SPJ.JNO = J.JNO
the AND S.CITY = 'Shanghai'

- not used to identify Tianjin production engineering part number
SELECT the DISTINCT SPJ.JNO
the FROM SPJ
the WHERE SPJ.JNO the NOT the IN (
the SELECT SPJ.JNO
the FROM SPJ, S
the WHERE SPJ.SNO = s.sno the AND S.CITY = 'Tianjin'
)

- all the parts of red color to blue
Update P
SET COLOR = 'Red'

- P6 J4 parts supplied from S5 to be supplied by the S3

update SPJ
set SNO=‘S3’
WHERE SNO='S5’AND JNO=‘J4’

Guess you like

Origin blog.csdn.net/weixin_43752167/article/details/90677140