SQL Interview Questions – Running Total For Different Genders

Spread the love

Problem Description –

Write an SQL query to find the total score for each gender on each day.

Return the result table ordered by gender and day in ascending order.

The query result format is in the following example.

Difficulty Level – Medium

Problem Link – Running Total

Solution –

    SUM(score_points) OVER(PARTITION BY gender ORDER BY day) as total
FROM Scores

Here, we have to simply use the SUM window function and partition the data by Gender and order the result by day in ascending order.

Rating: 1 out of 5.

Leave a Reply