Answer: Sorting and Calculations
Explore how to write SQL queries that sort and calculate data effectively. Understand the use of SELECT, WHERE, ORDER BY with calculations, COALESCE for NULL handling, and LIMIT to restrict results to master sorting and filtering techniques.
Solution
The solution is given below:
Explanation
The explanation of the solution code is given below:
Line 2: The
SELECTquery selectsStudentName,TheoryMarks,PracticalMarks, andCumulativeMarks.Line 3: The
FROMclause specifies the table name asStudentGrades.Line 4: The
WHEREclause selects the subject in hand.Line 5: The
ORDER BYclause is applied to the addition ofTheoryMarksandPracticalMarksand sorts the data in descending order. TheCOALESCE()function ensures that if there is aNULLvalue in the column, it is replaced with0...