DBMS LAB : Cycle-II
Lab Cycle - II Queries
1. Get Suppliers Names for Suppliers who supply at least one red part.
-->select sname from supplier where sno in(select sno from sp where pno in(select pno from parts where color='Red'));
Output:
| SNAME |
| Blake |
| Clark |
| Adams |
| Smith |
=============================================================================
2.Get Suppliers Names for Suppliers who do not supply part ‘P2’
--> select sname from supplier where sno in(select sno from sp where pno in(select pno from parts where pno!='P2'));
Output:
| SNAME |
| Blake |
| Clark |
| Adams |
| Jones |
| Smith |
=============================================================================
3. Using Group by with Having Clause, Get the part numbers for all the parts supplied by more than one supplier.
-->select pno,count(sno) from sp group by pno having count(sno)>1;
Output:
| PNO | COUNT(SNO) |
| P4 | 2 |
| P1 | 2 |
| P3 | 3 |
| P6 | 2 |
| P5 | 2 |
=============================================================================
4. Get supplier numbers for suppliers with status value less the current max status value.
-->select sno from supplier where status<(select max(status) from supplier);
Output
| SN |
| S1 |
| S2 |
| S4 |
=============================================================================
5. Get the Project numbers, whose parts are not in Red Color, from London.
--> select jno from projects where jno not in (select jno from spj where pno in (select pno from parts where color='Red' and city='London'));
Output
| JN |
| J5 |
| J6 |
=============================================================================
6. Get the suppliers located from the same city.
--> Select distinct s.sno,s.city from supplier s,supplier s1 where s.city>s1.city;
Output
| SN | CITY |
| S2 | Paris |
| S3 | Paris |
| S4 | London |
| S1 | London |
=============================================================================
7. Get the suppliers, who does not supply any part.
-->select sno,sname from supplier where sno not in(select sno from sp);
Output
No rows selected
=============================================================================
8. Find the pnames of parts supplied by London Supplier and by no one else.
--> select pname from parts where pno in (select pno from sp where sno in(select sno from supplier where city='London'));
Output
| PNAME |
| Nut |
| Cog |
=============================================================================
9. Find the sno’s of suppliers who charge more for some part than the average cost of all the parts.
--> select sno from supplier where sno in (select sno from sp where pno in (select pno from parts where cost>(select avg(cost) from parts)));
Output:
| SN |
| S3 |
| S5 |
| S2 |
=============================================================================
10. Find the sid’s of suppliers who supply only red parts.
--> select sno from sp minus select sno from sp where pno not in (select pno from parts where color='Red');
Output
| SN |
| S1 |
| S4 |
=============================================================================
Comments
Post a Comment