URI Online Judge Solution 2738 Contest Using PostgreSQL Query Language. The Mars Technology University has Open Positions for researchers. However, the computer responsible for processing the candidates' data is broken. You must present the candidate list, containing the name and final score (with two decimal places of precision) of each candidate. Remember to show the list ordered by score (highest first).
The score is given by the weighted average described as:
Schema
candidateColumn | Type |
id (PK) | integer |
name | varchar |
scoreColumn | Type |
candidate_id (FK) | integer |
math | numeric |
specific | numeric |
project_plan | numeric |
Tables
candidateid | name |
1 | Michael P Cannon |
2 | Barbra J Cable |
3 | Ronald D Jones |
4 | Timothy K Fitzsimmons |
5 | Ivory B Morrison |
6 | Sheila R Denis |
7 | Edward C Durgan |
8 | William K Spencer |
9 | Donna D Pursley |
10 | Ann C Davis |
scorecandidate_id | math | specific | project_plan |
1 | 76 | 58 | 21 |
2 | 4 | 5 | 22 |
3 | 15 | 59 | 12 |
4 | 41 | 42 | 99 |
5 | 22 | 90 | 9 |
6 | 82 | 77 | 15 |
7 | 82 | 99 | 56 |
8 | 11 | 4 | 22 |
9 | 16 | 29 | 94 |
10 | 1 | 7 | 59 |
Output Sample
name | avg |
Edward C Durgan | 74.10 |
Timothy K Fitzsimmons | 70.30 |
Donna D Pursley | 58.90 |
Sheila R Denis | 47.00 |
Michael P Cannon | 43.10 |
Ivory B Morrison | 35.90 |
Ann C Davis | 31.80 |
Ronald D Jones | 26.70 |
William K Spencer | 14.40 |
Barbra J Cable | 13.30 |
URI 2738 Solution in PostgreSQL:
SELECT Candidate.name,ROUND(((Score.math*2) + (specific*3) + (project_plan*5))/10,2) as avg
FROM Candidate
INNER JOIN Score
ON Candidate.id = Score.candidate_id
ORDER BY avg DESC
Comments
Post a Comment