1308. 不同性别每日分数总计
写一条SQL语句查询每种性别在每一天的总分。
返回按 gender 和 day 对查询结果 升序排序 的结果。
查询结果格式的示例如下。
题意:每个性别,每日后累加得分
方法一:
select
c1.gender,
c1.day,
sum(c2.score_points) as total
from
Scores c1 left join Scores c2 on c1.gender = c2.gender
where
c1.day >= c2.day
group by
1,2
order by
1,2
方法二:按照性别进行分组,再按照日期进行叠加求和(推荐)
select
gender,
day,
sum(score_points) over(partition by gender order by day) as total
from
Scores
order by
1,2