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

Info icon This 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.
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;
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
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.
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern