Informatics Practices
Consider the following table named "Student":
| RollNo | Name | Marks | Grade | Fees | Stream |
|---|---|---|---|---|---|
| 1 | Mishra | 30 | C | 6000 | Commerce |
| 2 | Gupta | 48 | B | 15000 | Arts |
| 3 | Khan | 66 | A | 4800 | Science |
| 4 | Chaddha | 24 | C | 12500 | Commerce |
| 5 | Yadav | 23 | A | 10000 | Arts |
Write the SQL functions which will perform the following operations:
(i) To show the sum of fees of all students.
(ii) To display maximum and minimum marks.
(iii) To count different types of grades available.
(iv) Write a query to count grade-wise total number of students.
Answer
(i)
SELECT SUM(Fees) AS Total_Fees
FROM Student;
Output
+------------+
| Total_Fees |
+------------+
| 48300 |
+------------+
(ii)
SELECT MAX(Marks) AS Max_Marks, MIN(Marks) AS Min_Marks
FROM Student;
Output
+-----------+-----------+
| Max_Marks | Min_Marks |
+-----------+-----------+
| 66 | 23 |
+-----------+-----------+
(iii)
SELECT COUNT(DISTINCT Grade) AS Different_Grades
FROM Student;
Output
+------------------+
| Different_Grades |
+------------------+
| 3 |
+------------------+
(iv)
SELECT Grade, COUNT(*) AS Total_Students
FROM Student
GROUP BY Grade;
Output
+-------+----------------+
| Grade | Total_Students |
+-------+----------------+
| C | 2 |
| B | 1 |
| A | 2 |
+-------+----------------+
Related Questions
Write the names of any two common types of Intellectual Property Rights which are protected by law.
Consider the dataframe SHOP given below:
Item Qty City Price 101 Biscuit 100 Delhi 10 102 Jam 110 Kolkata 25 103 Coffee 200 Kolkata 55 104 Sauce 56 Mumbai 55 105 Chocolate 170 Delhi 25Write commands to:
(i) Write short code to show the information having city = "Delhi".
(ii) Calculate Qty * Price and assign to column 'Net_Price'.
(iii) Display Items of all rows.
(i) Consider the dataframe "EMP":
Name Basic Da Hra E1 Sanya 9500 3000 2000 E2 Krish 7000 5000 1900 E3 Rishav 9650 1500 2100 E4 Deepak 7500 2000 2700 E5 Kriti 9200 1800 500Give the output
EMP.iloc[1, 2]=8000 EMP.Hra = EMP.Hra + 200 print(EMP)(ii) Write a Python statement to change the name 'Rishav' to 'Rishab' in the above dataframe.
Or
(Option for part ii only)
Write a Python statement to calculate the sum of Basic, Da, and Hra and assign it to the column 'Salary'.
Consider the following table named "GARMENT".
GCODE GNAME SIZE COLOUR PRICE 111 T-Shirt XL Red 1400.234 112 Jeans L Blue 1600.123 113 Skirt M Black 1100.65 115 Trousers L Brown 1500.50 116 Ladies Top L Pink 1200.25 Write SQL queries using SQL functions to perform the following operations:
(i) Display the name and price after rounding off to one decimal place.
(ii) Display all Gname in upper case.
(iii) Display the last three characters from Gname.
(iv) Display the highest Gcode from the table GARMENT.
(v) Display the sum of all prices of size 'L'.