返回介绍

solution / 2900-2999 / 2989.Class Performance / README_EN

发布于 2024-06-17 01:02:58 字数 3136 浏览 0 评论 0 收藏 0

2989. Class Performance

中文文档

Description

Table: Scores

+--------------+---------+
| Column Name  | Type  |
+--------------+---------+
| student_id   | int   |
| student_name | varchar |
| assignment1  | int   |
| assignment2  | int   |
| assignment3  | int   |
+--------------+---------+
student_id is column of unique values for this table.
This table contains student_id, student_name, assignment1, assignment2, and assignment3.

Write a solution to calculate the difference in the total score (sum of all 3 assignments) between the highest score obtained by students and the lowest score obtained by them.

Return _the result table in any order__._

The result format is in the following example.

 

Example 1:

Input: 
Scores table:
+------------+--------------+-------------+-------------+-------------+
| student_id | student_name | assignment1 | assignment2 | assignment3 |
+------------+--------------+-------------+-------------+-------------+
| 309    | Owen     | 88      | 47      | 87      |
| 321    | Claire     | 98      | 95      | 37      |   
| 338    | Julian     | 100     | 64      | 43      |  
| 423    | Peyton     | 60      | 44      | 47      |  
| 896    | David    | 32      | 37      | 50      | 
| 235    | Camila     | 31      | 53      | 69      | 
+------------+--------------+-------------+-------------+-------------+
Output
+---------------------+
| difference_in_score | 
+---------------------+
| 111         | 
+---------------------+
Explanation
- student_id 309 has a total score of 88 + 47 + 87 = 222.
- student_id 321 has a total score of 98 + 95 + 37 = 230.
- student_id 338 has a total score of 100 + 64 + 43 = 207.
- student_id 423 has a total score of 60 + 44 + 47 = 151.
- student_id 896 has a total score of 32 + 37 + 50 = 119.
- student_id 235 has a total score of 31 + 53 + 69 = 153.
student_id 321 has the highest score of 230, while student_id 896 has the lowest score of 119. Therefore, the difference between them is 111.

Solutions

Solution 1: Maximum and Minimum

We can use the MAX and MIN functions to get the maximum and minimum sums of assignment1, assignment2, and assignment3, respectively. Then, subtract the minimum from the maximum.

# Write your MySQL query statement below
SELECT
  MAX(assignment1 + assignment2 + assignment3) - MIN(
    assignment1 + assignment2 + assignment3
  ) AS difference_in_score
FROM Scores;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文