{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Qty as q frome spj where spjp p1 and spj s s1 2using

Info iconThis preview shows pages 26–30. Sign up to view the full content.

View Full Document Right Arrow Icon
SELECT SUM ( SPJ.QTY) AS Q FROME SPJ WHERE SPJ.P# = ‘P1’; AND SPJ .S# = ‘ S1’; 2.Using the supplier-part. Project tables above, write the SQL facilities for the following operations. (i) Get all combination of supplier and part information such that the supplier and part in question are colocated. (5-Marks) (ii) For each part supplied, get the part number and the total shipment quantity. (5-Marks) (iii) Get supplier numbers for suppliers with status less than the current maximum status in the S table. (5-Marks) (iv) Get supplier numbers for suppliers supplying some project with part P 1 in a quantity greater than the average shipment quantity of part P 1 for that project.
Background image of page 26

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
(5-Marks) Sol (i) SELECT SX,PX FORME S,P WHERE S.CITY = P. CITY; (ii) SELECT SPJ.P# , SUM ( SPJ.QTY) AS Q FROME SPJ GROUP BY SPJ.P#; (iii) SELECT S.S# FROME S WHERE S.STATCIS< ( SELECT MAX CS.STATUS) FROME S); (iv) SELECT SPJX.S# FROME SPJ AS SPJX WHERE SPJX.P# = ‘P1’ AND SPJX.QTY> ( SELECT AVG ( SPJ.QTY) FROM SPJ AS SPJY WHERE SPJY.P# = ‘P1’ AND SPJX.J# = SPJY.J#); 3. Using the supplier-part. Project tables above, write the SQL facilities for the following operations. (i) Get supplier names for suppliers who supply at least one red part. (5-Marks) (ii) Get part numbers for parts supplied by more than one supplier. (5-Marks) (iii) Get all cities in which at least one supplier, part, or project is located. (5-Marks) (iv) Get supplier names for suppliers who supply all parts. (5-Marks) Sol (i) SELECT DISTINCT S.SNAME FROME S,SPJ,P WHERE SPJ,P# = P.P# AND SPJ.S# = S.S# AND P.COLOR= ‘ PED’; (ii) SELECT SPJ .P# FROM SPJ GROUP SPJ.P# HAVING COUNT ( SPJ.S#)>1;
Background image of page 27
(iii) SELECT S.CITY FROM S CINION SELECT P.CITY FROM P CINION SELECT J.CITY FROM J; (iv) SELECT DISTINCT S.SAME FROM S WHERE NOT EXISTS ( SELECTP.* FROM P WHERE NOT EXISTS ( SELECT SPJ.* FROM SPJ WHERE SPJ.SH.S.S# AND SPJ.P# = P.P#)); 4. Using the supplier-part. Project tables above, write the SQL facilities for the following operations. (i) Get supplier numbers for suppliers supplying at least one part supplied by at least one supplier who supplies at least one red part. (5-Marks) (ii) Get supplier names for suppliers who supply part P 2 . (5-Marks) (iii) Get all pairs of supplier numbers such that the two suppliers concerned are colocated. (5-Marks) (iv) Get supplier names for suppliers who do not supply part P 2 . (5-Marks) Sol (i) SELECT DISTINCT SPJX.S# FROM SPJ AS SPJX,SPJ,SPJ AS SPJY,SPJ AS SPJZ,P WHERE SPJX.P# = SPJY.P# AND SPJY.S# = SPJZ.S# AND SPJZ.P# = P. P# AND P.COLOR = ‘ RED’; (ii) SELECT DISTNCT S.SNAME FROM S WHERE EXISTS ( SELECT SPJ.* FROM SPJ WHERE SPJ.P# = ‘P2’ AND SPJ.S# = S.S #); (iii) SELECT A.S# AS SA, B.S# AS SB
Background image of page 28

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
FROM S AS A, S AS B WHERE A.CITY = B. CITY AND A.S# < B. S#; ( iv) SELECT DISTINCT S.SNAME FROM S WHERE NOT EXISTS ( SELECT SPJ.* FROM SPJ WHERE SPJ.P# = ‘P2’ AND SPJ.S# = S. S#); 5.(a) How many categories in the integrity constraint and explain them. (8-Marks) (b) Let A and B be two relvars. State the candidate key(s) for each of the following.
Background image of page 29
Image of page 30
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page26 / 168

QTY AS Q FROME SPJ WHERE SPJP P1 AND SPJ S S1 2Using the...

This preview shows document pages 26 - 30. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online