TOTALTIME - Editorial

PROBLEM LINK:

Practice
Contest:

DIFFICULTY:

TBD

PREREQUISITES:

Basic SQL, Group By, Subqueries

PROBLEM:

Given all the submissions of a participant, you should find their Total Time, which is defined in the problem.

EXPLANATION:

We group the submissions based on which problem they are made on using GROUP BY. And within the submissions of a particular problem, we use WHERE to filter out only the Accepted submissions. And then use MIN to find the earliest Accepted submission for this problem, which is the ‘Time taken for a problem’ for this problem.

The above query serves as the subquery, and in the outer query, we use SUM to find the sum of the ‘Time taken for a problem’ of all the solved problems.

And remember to have the column alias set correctly.

Code
SELECT SUM(prob.PROBTIME) AS "TOTAL TIME"
FROM
    (SELECT MIN(seconds) AS PROBTIME
    FROM Submissions
    WHERE verdict = "Accepted"
    GROUP BY problem_name) prob;
1 Like