-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoring System
More file actions
61 lines (40 loc) · 1.36 KB
/
Scoring System
File metadata and controls
61 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
The math scores of each student have been stored in the STUDENT table. Write a query to print the ID and the NAME of each of the three highest scoring students.
Print the NAMEs in descending order by SCORE, then ascending order by ID for matching SCOREs.
Input Format
STUDENT
Name Type Description
ID Integer A student ID in the inclusive range [1, 1000]. This field is the primary key.
NAME String A student name. This field contains between 1 and 100 characters (inclusive).
SCORE Float The Math score of the student.
Output Format
The result should contain the IDs and the NAMEs of the three highest scoring students. Print the records in descending order by SCORE, then ascending order by ID for matching SCOREs.
STUDENT.ID STUDENT.NAME
Sample Input
STUDENT
ID NAME SCORE
1 Bob 50
2 John 65.5
3 Harry 45
4 Dick 85
5 Dev 25
6 Sid 98
7 Tom 90
8 Julia 70.5
9 Erica 81
10 Jerry 85
Sample Output
6 Sid
7 Tom
4 Dick
Explanation
The students are arranged in the descending order of their math scores, followed by the ascending order of their ids, as shown below:
Sid > Tom > Dick > Jerry > Erica > Julia > John > Bob > Harry > Dev
Dick's and Jerry's scores were the same, so they are shown in ID order.
/*
Enter your query below.
Please append a semicolon ";" at the end of the query
*/
// CODE
SELECT id, name
FROM student
ORDER BY student.score DESC, id ASC LIMIT 3;