Informatics Practices
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;
Relational Database
3 Likes
Answer
(a)
SELECT NAME FROM GRADUATE
WHERE `RANK` = 1;
Output
+--------+
| NAME |
+--------+
| KARAN |
| RAJ |
| DIVYA |
| GAURAV |
| VARUN |
| LIZA |
| PUJA |
+--------+
(b)
SELECT NAME
FROM GRADUATE
WHERE AVERAGE > 65;
Output
+--------+
| NAME |
+--------+
| KARAN |
| RAJ |
| GAURAV |
| LIZA |
+--------+
(c)
SELECT NAME
FROM GRADUATE
WHERE SUBJECT = 'COMPUTER' AND AVERAGE > 60;
Output
+------+
| NAME |
+------+
| LIZA |
+------+
(d)
SELECT NAME FROM GRADUATE
WHERE NAME LIKE "%a";
Output
+-------+
| NAME |
+-------+
| DIVYA |
| LIZA |
| PUJA |
| NISHA |
+-------+
(e)
SELECT * FROM GRADUATE WHERE Subject = "Physics";
Output
+-------+--------+---------+---------+---------+------+
| S.No. | name | stipend | subject | average | RANK |
+-------+--------+---------+---------+---------+------+
| 1 | KARAN | 400 | PHYSICS | 68 | 1 |
| 5 | GAURAV | 500 | PHYSICS | 70 | 1 |
| 9 | PUJA | 500 | PHYSICS | 62 | 1 |
+-------+--------+---------+---------+---------+------+
(f) Since 'RANK' is a reserved keyword in SQL, we encounter an error while running this query. To avoid such errors, we can enclose the column name 'RANK' in backticks to treat it as a literal identifier.
The corrected query is :
SELECT DISTINCT `RANK` FROM GRADUATE;
Output
+------+
| RANK |
+------+
| 1 |
| 2 |
+------+
Answered By
2 Likes
Related Questions
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)
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;
What is the difference between Candidate key and Alternate key?
What is the degree and cardinality of a table having 10 rows and 5 columns?