Skip to main content
All Questions

Calculate Test Scores

Medium
Unlock detailed company stats for this questionUpgrade

An organization has conducted SQL tests for all its backend developers. A developer could attempt a test multiple times. The organization wants to calculate the overall scores of the candidate for the SQL tests.

Write a query to print the employee_id, employee_name, and the total_score obtained by the developers. A developer's total_score is the sum of their maximum scores for all tests. If the developer has attempted a single test multiple times, consider the maximum score of all the attempts for that test.

Order the results in descending total_score. In case more than one developer has obtained a similar total_score, sort the results by ascending order of employee_id. The schema of the tables is described below.

tests +------+---------+ | id | int | <----------+ | name | varchar | | +------+---------+ | | employees | +------+---------+ | | id | int | <-------+ | | name | varchar | | | +------+---------+ | | | | test_results | | +-------------+---------+ | | | id | int | | | | employee_id | int | -+ | | test_id | int | ----+ | score | decimal | +-------------+---------+

Related courses

Course

Data Analyst Interview Prep

Ace your data analyst interviews—whether you're targeting product, marketing, or business analyst roles. Tackle real take-home case studies, sharpen your technical and dashboarding skills, and get strategies from interviewers at top tech companies and startups.

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.