a
This commit is contained in:
33
Semester 2/SQL Hell pt3.txt
Normal file
33
Semester 2/SQL Hell pt3.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
/* list suppliers who have QTYs greater than the the QTYs of s4 */
|
||||
select snumber, qty
|
||||
from spj
|
||||
where qty > ALL
|
||||
(select qty
|
||||
from spj
|
||||
where snumber = 's4');
|
||||
|
||||
|
||||
/*List suppliers who have qty smaller than any qty of s2*/
|
||||
|
||||
SELECT snumber, qty
|
||||
FROM spj
|
||||
WHERE qty < ANY(SELECT qty FROM spj WHERE snumber = "s2");
|
||||
|
||||
/*List the snumber and QTYs of the supplier who relates with the snumber to the QTYs that are greater than the AVG QTYs of the particular supplier.
|
||||
i.e. for s1 the AVG of all its QTY is x... You must list all the QTYs of s1 that are greater than x.
|
||||
*/
|
||||
select snumber, qty
|
||||
from spj as a
|
||||
where qty >
|
||||
(select avg(qty)
|
||||
from spj
|
||||
where a.snumber = snumber);
|
||||
|
||||
|
||||
/* EXISTS demo */
|
||||
|
||||
select *
|
||||
from supplier a
|
||||
where not EXISTS
|
||||
(select * from spj
|
||||
where snumber = a.snumber);
|
45
Semester 2/SQL Hell pt4.txt
Normal file
45
Semester 2/SQL Hell pt4.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
/* What are the suppliers that supply all parts using NOT EXISTS */
|
||||
/* sp difference A */
|
||||
select DISTINCT snumber
|
||||
from spj as c
|
||||
where not EXISTS
|
||||
/* A */
|
||||
/* Cross Product */
|
||||
(select DISTINCT b.snumber
|
||||
from part as a cross join spj as b
|
||||
where c.snumber = b.snumber and not EXISTS
|
||||
/* difference cross product sp */
|
||||
(select snumber, pnumber from spj
|
||||
where b.snumber = spj.snumber and a.pnumber = spj.pnumber));
|
||||
|
||||
|
||||
/* What are the suppliers that supply all parts using NOT EXISTS * */
|
||||
/* sp difference A */
|
||||
select DISTINCT snumber
|
||||
from spj as c
|
||||
where not EXISTS
|
||||
/* A */
|
||||
/* Cross Product */
|
||||
(select *
|
||||
from part as a cross join spj as b
|
||||
where c.snumber = b.snumber and not EXISTS
|
||||
/* difference cross product sp */
|
||||
(select * from spj
|
||||
where b.snumber = spj.snumber and a.pnumber = spj.pnumber));
|
||||
|
||||
|
||||
/* What are the suppliers that supply all parts using NOT EXISTS *, list their names and their cities */
|
||||
select snumber, sname, city from supplier
|
||||
WHERE snumber in
|
||||
(/* sp difference A */
|
||||
select DISTINCT snumber
|
||||
from spj as c
|
||||
where not EXISTS
|
||||
/* A */
|
||||
/* Cross Product */
|
||||
(select *
|
||||
from part as a cross join spj as b
|
||||
where c.snumber = b.snumber and not EXISTS
|
||||
/* difference cross product sp */
|
||||
(select * from spj
|
||||
where b.snumber = spj.snumber and a.pnumber = spj.pnumber)));
|
Reference in New Issue
Block a user