php - 如何设计管理A组和B组之间交叉排名的Mysql表?

标签 php mysql sql sql-server

好的,这是公司的要求。

A公司有2个A、B组,A组有N人,B组有M人。

每组中的每个人都会对另一组中最多 5 人进行从 1 到 5 的等级排名。

每个人不得对任何人进行排名或排名少于 5 人。

一个群体中的一个人不得与其他群体中的不同人处于同一级别。这意味着 5 个级别中的每个级别都必须与自己的人一起进行,因此每个级别不得与 2 个不同的人一起进行。

在所有人都进行了排名之后。然后,经理检查第一轮获胜的对子。如果一个小组中的一个人为其他小组中的其他人排名,而另一个人为同一个人排名相同,则获胜对。

之后A组和B组继续排名,但这次系统应该将第一轮获胜的组合移出名单。

这就是我设计的 mysql DB。

GroupA Table
groupAPersonID - ranking level - groupBPersonID - roundNo - winningPair
1              - 1             - 3              - 1       - y
1              - 2             - 2              - 1     
1              - 3             - 4              - 1     
1              - 4             - 1              - 1
1              - 5             - 8              - 1     
2              - 1             - 2              - 1     
2              - 2             - 3              - 1     
2              - 3             - 5              - 1     
2              - 4             - 8              - 1
2              - 5             - 8              - 1 ---> illegal record cos groupBPersonID "8" has 2 Level 4 & 5

GroupB Table
groupBPersonID - ranking level - groupAPersonID - roundNo - winningPair
1              - 1             - 6              - 1     
1              - 2             - 4              - 1     
1              - 3             - 5              - 1     
1              - 4             - 1              - 1
1              - 5             - 8              - 1     
3              - 1             - 1              - 1       - Y     
3              - 2             - 2              - 1     
3              - 3             - 8              - 1     
3              - 4             - 3              - 1
3              - 4             - 6              - 1 --> illegal record cos the Level 4 that was rankled by groupBPersonID "3" appears 2 times

注意:groupAPersonID“1”和groupBPersonID“3”是获胜对,因为groupAPersonID“1”为groupAPersonID“3”排名第一,groupBPersonID“3”为groupAPersonID“1”排名第一。因此groupAPersonID“1”和groupBPersonID“3”不得出现在第二轮中。

GroupA Table
groupAPersonID - ranking level - groupBPersonID - roundNo - winningPair
...continue from the about data...
2              - 1             - 2              - 2     
2              - 2             - 3              - 2 --> illegal record cos  groupBPersonID "3" won the first round    
2              - 3             - 5              - 2   

GroupB Table
groupBPersonID - ranking level - groupAPersonID - roundNo - winningPair
...continue from the about data...
3              - 2             - 4              - 2 --> illegal record cos  groupBPersonID "3" won the first round    
1              - 2             - 1              - 2 --> illegal record cos  groupAPersonID "1" won the first round    

如果我设计两个这样的表,那么我需要在编程级别控制插入的记录,因为用户可以插入非法记录。

我不确定我的设计是否正确。

你能想出其他优雅的设计来解决这个问题吗?

最佳答案

您的设计未标准化,因此我首先将这两个表合并为一个表,如下所示:

EmployeeRanks
-------------
FromPersonId
ToPersonID
Ranking
Round

并创建一个新表,将员工与组进行匹配:

GroupEmployees 
---------------
Group
PersonId

关于php - 如何设计管理A组和B组之间交叉排名的Mysql表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25958930/

相关文章:

sql - 如何获取某个用户拥有同一组好友的uid? (SQL)

PHP fatal error : Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:

php - 使用 imap 通过 php 打开电子邮件给我这个错误 Message : imap_open() [function. imap-open] : Couldn't open stream {imap. gmail.com:993/imap/ssl}INBOX

php - 在将用户重定向到另一个网页后显示消息

python - pip install mysql-python错误

MYSQL 与Where 和Like And not in

python - 我使用 python mysql API 将数据插入 mysql 但当我没有添加语句 'with conn:' 时它不起作用

PHP字符串解析错误,变量后有必要的分号

PHP使用explode从数据库中提取属性

mysql - 大表复合索引,优化聚合查询