Professional Documents
Culture Documents
DBMS SQL
DBMS SQL
DBMS SQL
sql
Who has access
System properties
Type
SQL
Size
7 KB
Storage used
7 KB
Location
MySQL
Owner
Geek n Tech Hindi
Modified
Apr 11, 2019 by Geek n Tech Hindi
Opened
12:20 AM by me
Created
Apr 11, 2019
No description
Viewers can download
create table suppliers
(
sno varchar(5) primary key,
sname varchar(30),
status int(5),
scity varchar(10)
);
+------+-------+--------+----------+
| sno | sname | status | scity |
+------+-------+--------+----------+
| s101 | s1 | 18 | new york |
| s102 | s2 | 20 | london |
| s103 | s3 | 25 | paris |
| s104 | s4 | 28 | london |
| s105 | s5 | 30 | paris |
+------+-------+--------+----------+
5 rows in set (0.06 sec)
+------+---------+----------+
| jno | jname | jcity |
+------+---------+----------+
| j101 | main | new york |
| j102 | action | london |
| j103 | nothing | paris |
| j104 | zoom | london |
| j105 | game | paris |
+------+---------+----------+
5 rows in set (0.00 sec)
create table shipment
(
s_sno varchar(5),
s_pno varchar(5),
s_jno varchar(5),
quantity float(5),
primary key (s_sno, s_pno, s_jno),
foreign key(s_sno) references suppliers(sno),
foreign key(s_pno) references parts(pno),
foreign key(s_jno) references project(jno)
);
+------+--------+
| sno | status |
+------+--------+
| s103 | 25 |
| s105 | 30 |
+------+--------+
2 rows in set (0.05 sec)
c) select sno, sname from suppliers, parts, shipment where parts.pname='P2' and
suppliers.sno=shipment.s_sno and parts.pno=shipment.s_pno;
+------+-------+
| sno | sname |
+------+-------+
| s102 | s2 |
+------+-------+
1 row in set (0.00 sec)
d) select sno, sname from suppliers, parts, shipment where suppliers.sno=shipment.s_sno and
parts.pno=shipment.s_pno and not parts.pname='p2';
+------+-------+
| sno | sname |
+------+-------+
| s101 | s1 |
| s103 | s3 |
| s104 | s4 |
| s105 | s5 |
+------+-------+
e) select s_sno, s_pno, s_jno, parts.pweight*shipment.quantity as " shipment" from shipment, parts
where parts.pno=shipment.s_pno;
+-------+-------+-------+----------+
| s_sno | s_pno | s_jno | shipment |
+-------+-------+-------+----------+
| s101 | p101 | j101 | 4000 |
| s102 | p102 | j102 | 5850 |
| s103 | p103 | j103 | 12800 |
| s104 | p104 | j104 | 6000 |
| s105 | p105 | j105 | 3300 |
+-------+-------+-------+----------+
5 rows in set, 1 warning (0.05 sec)
+-------+-------+-------+----------+
| s_sno | s_pno | s_jno | quantity |
+-------+-------+-------+----------+
| s102 | p102 | j102 | 325 |
| s104 | p104 | j104 | 400 |
| s105 | p105 | j105 | 300 |
+-------+-------+-------+----------+
3 rows in set (0.02 sec)
+------+
| pno |
+------+
| p101 |
| p102 |
| p103 |
| p104 |
| p105 |
+------+
5 rows in set (0.01 sec)
h) select pcity from parts, shipment where parts.pno=shipment.s_pno and parts.pcolor='red' and
shipment.quantity>5;
+--------+
| pcity |
+--------+
| london |
+--------+
1 row in set (0.00 sec)
i) select pno, pname, pcolor, pcity, pweight from parts, shipment, suppliers where
suppliers.sno=shipment.s_sno and shipment.s_pno=parts.pno and suppliers.scity='london';
+------+-------+--------+--------+---------+
| pno | pname | pcolor | pcity | pweight |
+------+-------+--------+--------+---------+
| p102 | p2 | white | london | 18 |
| p104 | p4 | red | london | 15 |
+------+-------+--------+--------+---------+
2 rows in set (0.00 sec)
j) select pno from parts, suppliers, shipment, project where project.jcity='london' and
suppliers.scity='london' and suppliers.sno=shipment.s_sno and shipment.s_pno= parts.pno and
project.jno=shipment.s_jno;
+------+
| pno |
+------+
| p102 |
| p104 |
+------+
2 rows in set (0.00 sec)
k) select count(jno) from suppliers, shipment, project where suppliers.sno = shipment.s_sno and
project.jno=shipment.s_jno and suppliers.sname='s1' group by jno;
+------------+
| count(jno) |
+------------+
| 1|
+------------+
1 row in set (0.03 sec)
l) select sum(quantity) from suppliers, parts, shipment where suppliers.sname = 's1' and
parts.pname='p1' and suppliers.sno=shipment.s_sno and parts.pno = shipment.s_pno group by sno;
+---------------+
| sum(quantity) |
+---------------+
| 200 |
+---------------+