To write a SQL query that shows both the maximum and minimum marks from a student table, you can use the MAX() and MIN() aggregate functions in a SELECT statement. Here's a basic example:
SELECT
MAX(marks) AS MaxMarks,
MIN(marks) AS MinMarks
FROM
student;
Explanation:
MAX(marks): Returns the highest value in themarkscolumn.MIN(marks): Returns the lowest value in themarkscolumn.student: The table where the data is stored (assuming the table is namedstudent).
Example output:
| MaxMarks | MinMarks |
|---|---|
| 98 | 35 |
This query will return a single row with the maximum and minimum marks from the marks column in the student table.
If you want the result for each student:
If you'd like to display the maximum and minimum marks for each student, assuming there's a column like student_id or name, you can group by the student identifier. Here's an example:
SELECT
student_id,
MAX(marks) AS MaxMarks,
MIN(marks) AS MinMarks
FROM
student
GROUP BY
student_id;
This will return the maximum and minimum marks for each student based on their unique student_id.
No comments:
Post a Comment