- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设您有一个多项目竞赛,参赛者可以任意次数地尝试任何项目。 (很奇怪,我知道。)
如何为每个事件拉出所需玩家的最佳时间,并为其分配一个位置? (第一第二第三...)
Data example: Desired output:
Name | Event | Score Name | Event | Score | Rank
-------------------- ----------------------------
Bob 1 50 Given input: "Bob"
Bob 1 100 Bob 1 100 1
Bob 2 75 Bob 2 75 3
Bob 3 80 Bob 3 80 2
Bob 3 65
Given input: "Jill"
Jill 2 75 Jill 2 90 1
Jill 2 90 Jill 3 60 3
Jill 3 60
Given input: "Chris"
Chris 1 70 Chris 1 70 2
Chris 2 50 Chris 2 85 2
Chris 2 85 Chris 3 100 1
Chris 3 100
这是我之前问题的基础: Multi-event tournament standings
我感觉对这个问题的理解好多了(谢谢!),但我无法弥合这个版本问题的差距。
我有 SQL 5.x,所以我不能使用像 Rank() 这样的东西。这也将处理成千上万的分数。
最佳答案
可以通过此查询获得所需的输出:
select
IF(event is NULL, CONCAT('Given input: "', name,'"'), name) as name,
IF(event is NULL, '', event) as event,
IF(event is NULL, '', max(score)) as score,
IF(event is NULL, '', (
select count(s2.name) + 1
from (
select name, max(score) as score
from scores es
where es.event = s.event
group by es.name
order by score desc
) s2
where s2.score > max(s.score)
)) as `rank`
from scores s
group by name, event with rollup
having name is not NULL
order by name, event;
和输出(如果在 mysql cli 中运行查询):
+----------------------+-------+-------+------+
| name | event | score | rank |
+----------------------+-------+-------+------+
| Given input: "Bob" | | | |
| Bob | 1 | 100 | 1 |
| Bob | 2 | 75 | 3 |
| Bob | 3 | 80 | 2 |
| Given input: "Chris" | | | |
| Chris | 1 | 70 | 2 |
| Chris | 2 | 85 | 2 |
| Chris | 3 | 100 | 1 |
| Given input: "Jill" | | | |
| Jill | 2 | 90 | 1 |
| Jill | 3 | 60 | 3 |
+----------------------+-------+-------+------+
11 rows in set, 3 warnings (0.00 sec)
应该适用于任何 Mysql 5。
关于mysql - 多项目锦标赛排名(任意数量的参赛作品),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56227692/
假设你有两个类A和B。如果它们之间的关系是has-a 即A 有一个 B 如何将信息从 B 传递到 A?例如,假设您在 B 中进行了计算并需要 A 中的答案。 除了将 A 类的指针传递给 B 类并调用一
我正在尝试创建一个随机用户名生成器,当用户单击“gen-button”时,它应该会为他们提供一个随机用户名。我是 javascript 的新手,所以不胜感激:) var nameList = [
我知道这不是一个支持论坛;我正试图将其作为文档请求偷偷放入。 简短的问题:创建在所有方面都与原生元素完全相同的元素的推荐方法是什么? (提供附加功能,是的,但是是 100% 兼容的直接替换原生的) 长
面临一个问题 - 是否真的可以将动态选择属性传递给 FindAll 方法?它不起作用,因为它没有得到认可。 selectAttributes= "'x_name','y_name','z_name',
我有以下代码: function example(){ executing_code; $(function(){ executing_code; }); (function(){ executing
将 apache 版本(5.6.12)升级到最新版本后,mysql 在导入转储文件时返回重复错误。 简单的问题是如何导出适用于所有php mysql和mysql的mysql转储文件。 将文件导入到:服
这个 js fiddle 运行没有错误或问题: http://jsfiddle.net/3j45B/2/ 但是,当嵌入到 http://www.zabb.co.uk/untitled6.html 中时
我有一个脚本可以更新数据库中的日期字段。 (已购买)。 我还在另一部分中使用该数据更新第二个日期字段,该字段采用输入日期并添加 6 年 $duedate。它工作正常,但我收到变量 purchased
这个问题在这里已经有了答案: Logical Operators in C (8 个答案) 关闭 9 年前。 main( ) { int i = 4, j = -1, k = 0, w,
我从 http://en.wikipedia.org/wiki/NOP 中红色定义但我仍然需要一个更简单的定义。 我偶然发现了一段代码,但我不知道它到底做了什么: switch (Something)
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 2年前关闭。 Improve thi
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
嘿伙计们,我是一个新人,试图找出一些令人困惑的方法 var delay = (function(){ var timer = 0; return function(ca
我已经根据 MediaRecorder.isTypeSupported 对此进行了研究 Chromium 不支持音频/ogg;编解码器=作品。有谁知道是否有与 MediaRecorder 一起使用的替
我已经根据 MediaRecorder.isTypeSupported 对此进行了研究 Chromium 不支持音频/ogg;编解码器=作品。有谁知道是否有与 MediaRecorder 一起使用的替
我目前正在开发一个 VOIP 应用程序。为此,我使用 PortAudio 库检索和播放声音,并使用 Opus 库编码和解码声音数据包。 目前,我成功地使用了 PortAudio。我的程序只是做: 从麦
当我运行此代码时,它会抛出一个错误,指出“clear”未被识别为内部或外部命令。 #include #include void main() { int a=20; printf("print a n
我想知道下面这行代码是如何工作的? char c = (char) -98; 据我所知,所有有符号数都以2 的补码 形式存储。所以 -98 将以 2 的补码形式存储。因此,如果您键入将其转换为 cha
我在我的 OSX 应用程序中发现了一个问题,我认为这是 Mavericks 的错误。 我有以下层次结构: NSView->NSScrollView->NSClipView->NSTableView 当
这是我驱动器上的地址: C:\Program Files\Java\jdk1.6.0_18\bin 我将如何设置路径变量,以便我可以进入命令窗口 (windowskey+r "cmd") 并能够键入如
我是一名优秀的程序员,十分优秀!