LeetCode(数据库)- 不同性别每日分数总计
Posted 程序员牧码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(数据库)- 不同性别每日分数总计相关的知识,希望对你有一定的参考价值。
题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1)
SELECT s1.gender, s1.day, SUM(s2.score_points) AS total
FROM Scores AS s1, Scores AS s2
WHERE s1.gender = s2.gender AND s1.day >= s2.day
GROUP BY s1.gender, s1.day
ORDER BY s1.gender, s1.day;
-- 解决方案(2)
SELECT gender, day, SUM(score_points) OVER w AS total
FROM Scores
WINDOW w AS (PARTITION BY gender ORDER BY day);
-- 解决方案(3)
SELECT gender, day, SUM(score_points) OVER(PARTITION BY gender ORDER BY gender, day) total
FROM Scores
以上是关于LeetCode(数据库)- 不同性别每日分数总计的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode:Database 80.不同性别每日分数总计
每日SQL打卡DAY 25丨不同性别每日分数总计难度中等
每日SQL打卡DAY 25丨不同性别每日分数总计难度中等