Informatics Practices
Consider the given table and answer the questions.
Table: SchoolBus
| Rtno | Area_Covered | Capacity | Noofstudents | Distance | Transporter | Charges |
|---|---|---|---|---|---|---|
| 1 | Vasant Kunj | 100 | 120 | 10 | Shivam Travels | 3500 |
| 2 | Hauz Khas | 80 | 80 | 10 | Anand Travels | 3000 |
| 3 | Pitampura | 60 | 55 | 30 | Anand Travels | 4500 |
| 4 | Rohini | 100 | 90 | 35 | Anand Travels | 5000 |
| 5 | Yamuna Vihar | 50 | 60 | 20 | Bhalla Travels | 3800 |
| 6 | Krishna Nagar | 70 | 80 | 30 | Yadav Travels | 4000 |
| 7 | Vasundhara | 100 | 110 | 20 | Yadav Travels | 3500 |
| 8 | Paschim Vihar | 40 | 40 | 20 | Speed Travels | 3200 |
| 9 | Saket | 120 | 120 | 10 | Speed Travels | 3500 |
| 10 | Janakpuri | 100 | 100 | 20 | Kisan Tours | 3500 |
(a) To show all information of schoolbus where capacity is more than 70.
(b) To show area_covered for buses covering more than 20 km., but charges less than 4000.
(c) To display the details of school Bus having no. of students less than 50.
(d) To show Rtno, Area_Covered and Average cost per student for all routes where average cost per student is—Charges/Noofstudents.
(e) Add a new record with the following data:
(11, "Motibagh", 35, 32, 10, "Kisan Tours", 3500)
Relational Database
5 Likes
Answer
(a)
SELECT * FROM SCHOOLBUS WHERE CAPACITY > 70;
Output
+------+--------------+----------+--------------+----------+----------------+---------+
| RTNO | AREA_COVERED | CAPACITY | NOOFSTUDENTS | DISTANCE | TRANSPORTER | CHARGES |
+------+--------------+----------+--------------+----------+----------------+---------+
| 1 | VASANT KUNJ | 100 | 120 | 10 | SHIVAM TRAVELS | 3500 |
| 2 | HAUZ KHAS | 80 | 80 | 10 | ANAND TRAVELS | 3000 |
| 4 | ROHINI | 100 | 90 | 35 | ANAND TRAVELS | 5000 |
| 7 | VASUNDHARA | 100 | 110 | 20 | YADAV TRAVELS | 3500 |
| 9 | SAKET | 120 | 120 | 10 | SPEED TRAVELS | 3500 |
| 10 | JANAKPURI | 100 | 100 | 20 | KISAN TOURS | 3500 |
+------+--------------+----------+--------------+----------+----------------+---------+
(b)
SELECT AREA_COVERED FROM SCHOOLBUS WHERE DISTANCE > 20 AND CHARGES < 4000;
(c)
SELECT * FROM SCHOOLBUS WHERE NOOFSTUDENTS < 50;
Output
+------+---------------+----------+--------------+----------+---------------+---------+
| RTNO | AREA_COVERED | CAPACITY | NOOFSTUDENTS | DISTANCE | TRANSPORTER | CHARGES |
+------+---------------+----------+--------------+----------+---------------+---------+
| 8 | PASCHIM VIHAR | 40 | 40 | 20 | SPEED TRAVELS | 3200 |
+------+---------------+----------+--------------+----------+---------------+---------+
(d)
SELECT RTNO, AREA_COVERED, (CHARGES/NOOFSTUDENTS) AS AVERAEG_COST
FROM SCHOOLBUS;
Output
+------+---------------+--------------+
| RTNO | AREA_COVERED | AVERAEG_COST |
+------+---------------+--------------+
| 1 | VASANT KUNJ | 29.1667 |
| 2 | HAUZ KHAS | 37.5000 |
| 3 | PITAMPURA | 81.8182 |
| 4 | ROHINI | 55.5556 |
| 5 | YAMUNA VIHAR | 63.3333 |
| 6 | KRISHNA NAGAR | 50.0000 |
| 7 | VASUNDHARA | 31.8182 |
| 8 | PASCHIM VIHAR | 80.0000 |
| 9 | SAKET | 29.1667 |
| 10 | JANAKPURI | 35.0000 |
+------+---------------+--------------+
(e)
INSERT INTO SCHOOLBUS
VALUES(11, "MOTIBAGH", 35, 32, 10, "KISAN TOURS", 3500);
Answered By
3 Likes
Related Questions
What do you understand by the terms Cardinality and Degree of a relation in relational database?
Differentiate between DDL and DML. Mention the two commands for each category.
Write SQL commands for (a) to (d) and write the output for (e) on the basis of the following table:
Table: FURNITURE
S NO ITEM TYPE DATEOFSTOCK PRICE DISCOUNT 1 WhiteLotus DoubleBed 2002-02-23 3000 25 2 Pinkfeathers BabyCot 2002-01-29 7000 20 3 Dolphin BabyCot 2002-02-19 9500 20 4 Decent OfficeTable 2002-02-01 25000 30 5 Comfortzone DoubleBed 2002-02-12 25000 30 6 Donald BabyCot 2002-02-24 6500 15 (a) To list the details of furniture whose price is more than 10000.
(b) To list the Item name and Price of furniture whose discount is between 10 and 20.
(c) To delete the record of all items where discount is 30.
(d) To display the price of 'Babycot'.
(e) Select Distinct Type from Furniture;
Write SQL commands for (a) to (d) and write the output for (e) and (f) on the basis of given table GRADUATE:
Table: GRADUATE
S NO NAME STIPEND SUBJECT AVERAGE RANK 1 KARAN 400 PHYSICS 68 1 2 RAJ 450 CHEMISTRY 68 1 3 DEEP 300 MATHS 62 2 4 DIVYA 350 CHEMISTRY 63 1 5 GAURAV 500 PHYSICS 70 1 6 MANAV 400 CHEMISTRY 55 2 7 VARUN 250 MATHS 64 1 8 LIZA 450 COMPUTER 68 1 9 PUJA 500 PHYSICS 62 1 10 NISHA 300 COMPUTER 57 2 (a) List the names of those students who have obtained rank 1.
(b) Display a list of all those names whose average is greater than 65.
(c) Display the names of those students who have opted for computer as a subject with average of more than 60.
(d) List the names of all students whose name ends with 'a'.
(e) SELECT * FROM GRADUATE WHERE Subject = "Physics";
(f) SELECT DISTINCT RANK FROM GRADUATE;