鱼C论坛

 找回密码
 立即注册
查看: 1530|回复: 0

MYSQL错题整理(1308. 不同性别每日分数总计)

[复制链接]
发表于 2020-3-29 11:06:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 糖逗 于 2020-7-2 16:21 编辑

题目描述:
  1. 写一条SQL语句查询每种性别在每一天的总分,并按性别和日期对查询结果排序

  2. 下面是查询结果格式的例子:

  3. Scores表:
  4. +-------------+--------+------------+--------------+
  5. | player_name | gender | day        | score_points |
  6. +-------------+--------+------------+--------------+
  7. | Aron        | F      | 2020-01-01 | 17           |
  8. | Alice       | F      | 2020-01-07 | 23           |
  9. | Bajrang     | M      | 2020-01-07 | 7            |
  10. | Khali       | M      | 2019-12-25 | 11           |
  11. | Slaman      | M      | 2019-12-30 | 13           |
  12. | Joe         | M      | 2019-12-31 | 3            |
  13. | Jose        | M      | 2019-12-18 | 2            |
  14. | Priya       | F      | 2019-12-31 | 23           |
  15. | Priyanka    | F      | 2019-12-30 | 17           |
  16. +-------------+--------+------------+--------------+
  17. 结果表:
  18. +--------+------------+-------+
  19. | gender | day        | total |
  20. +--------+------------+-------+
  21. | F      | 2019-12-30 | 17    |
  22. | F      | 2019-12-31 | 40    |
  23. | F      | 2020-01-01 | 57    |
  24. | F      | 2020-01-07 | 80    |
  25. | M      | 2019-12-18 | 2     |
  26. | M      | 2019-12-25 | 13    |
  27. | M      | 2019-12-30 | 26    |
  28. | M      | 2019-12-31 | 29    |
  29. | M      | 2020-01-07 | 36    |
  30. +--------+------------+-------+

  31. 来源:力扣(LeetCode)
  32. 链接:https://leetcode-cn.com/problems/running-total-for-different-genders
  33. 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
复制代码


  1. select s1.gender,s1.day,sum(s2.score_points) as total
  2. from scores as s1 join scores as s2
  3. where s1.gender=s2.gender and s1.day>=s2.day
  4. group by s1.gender,s1.day
复制代码



其他参考:
1.窗口函数,但MYSQL实现不了。
https://blog.csdn.net/qq_41805514/article/details/81772182

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 19:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表