cswork / libraryOpen practice workspace

Coding questions · IBM

Write SQL to compute max and min marks

This question evaluates a candidate's ability to perform basic data aggregation in SQL, specifically computing summary statistics from a single table. It is commonly asked to assess competence in data manipulation and query result shaping within the Data Manipulation (SQL/Python) domain, focusing on practical application of SQL aggregation rather than purely conceptual theory.

Tables

marks

columntypenotes
student_idINTprimary key
marksINTnot null

Task

Write a SQL query that returns a single row with:

  • max_marks: the maximum value of marks
  • min_marks: the minimum value of marks

Output

A single row with columns (max_marks, min_marks).

Compute Maximum and Minimum Marks

You are given a table named marks that stores students' marks. Write a SQL query to return the maximum mark and the minimum mark from the table.

Return exactly two columns:

  • max_marks: the maximum value of marks
  • min_marks: the minimum value of marks

Table marks

columntypeconstraints
student_idINTPRIMARY KEY, NOT NULL
marksINTNOT NULL

Sample data:

marksstudent_id
88101
74102
95103
60104
95105
82106

Expected output

A single-row result with the maximum and minimum marks across all rows in the marks table.

max_marksmin_marks
9560

Hints

  1. Use aggregate functions to compute the max and min across all rows.
  2. The result should be a single row with two columns.