2014-09-21 39 views
0

好的,这是公司的要求。如何设计管理组A和组B之间交叉排名的Mysql表?

公司A有2个A组& B. A组有N个人& B组有M个人。

每个组中的每个人将从1到5的等级中排列,最多5个人在相反组中。

每个人不得排列任何人或排名少于5人。

组中的人不得将不同的人对同一等级分配给其他组。这意味着5个等级中的每个等级必须与其自己的人一起出行,因此每个等级不得与2个不同的人一起出发。

毕竟人们做了他们的排名。然后经理在第一轮检查赢得的对。如果一个团队中的某个人为另一个团体中的其他人排列了一个等级,并且另一个人排列了同一个等级的同一个人,那么这个团队将成为赢家。

在此之后,A,B组继续排名,但此时系统应消除在第一轮获胜的对,淘汰之列。

因此,这里是我设计mysql数据库。

 
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” 中奖对COS groupAPersonID “1” 排名第1级为groupBPersonID “3” & groupBPersonID “3” 中排名第1级为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  

如果我用2台这样的设计,然后我需要在编程水平来控制插入的记录是用户可以插入违法记录。

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

你能拿出其他优雅的设计来管理这个问题吗?

回答

1

你的设计不是标准化的,所以我将与这两个表中的一个这样的组合开始:

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

,并创建一个新表,将匹配的员工群体:

GroupEmployees 
--------------- 
Group 
PersonId 
+0

但如何控制非法记录? – Tum 2014-09-21 13:02:53

+0

我想你应该在它到达数据库之前控制它。否则,在飞行中计算它。 – Bulat 2014-09-21 13:16:09

相关问题