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
| column | type | notes |
|---|---|---|
| student_id | INT | primary key |
| marks | INT | not null |
Task
Write a SQL query that returns a single row with:
max_marks: the maximum value ofmarksmin_marks: the minimum value ofmarks
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 ofmarksmin_marks: the minimum value ofmarks
Table marks
| column | type | constraints |
|---|---|---|
| student_id | INT | PRIMARY KEY, NOT NULL |
| marks | INT | NOT NULL |
Sample data:
| marks | student_id |
|---|---|
| 88 | 101 |
| 74 | 102 |
| 95 | 103 |
| 60 | 104 |
| 95 | 105 |
| 82 | 106 |
Expected output
A single-row result with the maximum and minimum marks across all rows in the marks table.
| max_marks | min_marks |
|---|---|
| 95 | 60 |
Hints
- Use aggregate functions to compute the max and min across all rows.
- The result should be a single row with two columns.