本文介绍了检查sql server表中的列值,比较它们并插入不同的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有两张桌子



(Prefrences_Table)



I have two tables in my database

(Prefrences_Table)

--------------------------
|student | Preferences |
--------------------------
Stud A   |  Stud B  
Stud A   |  Stud C
Stud B   |  Stud E
Stud B   |  Stud A
Stud C   |  Stud F
Stud F   |  Stud B
--------------------------







(Prefrences_Table)




(Prefrences_Table)

--------------------------
    |student | Group ID/Name |
    --------------------------
    Stud A   |    
    Stud B   |  
    Stud C   |  
    Stud D   |  
    Stud E   |  
    Stud F   |  
    --------------------------





我要求每个学生最多给我7个名字,他们想和谁合作。然后在帐户中获取这些信息尽可能多地做出选择并创建一个团队。



这些是我必须遵循的规则来创建团队。



首先,我将检查Stud A是否在他的偏好列表中添加了Stud B,并且stud B在他的偏好中添加了stud A,如果两者都是他们互相添加了我想在团队/团队中添加它们(为所有学生这样做)。第二,检查单侧偏好,Stud A在他的偏好中添加了Stud B但是B没有,并将它们添加到组中。第三,将所有学生添加到随机组中。每个团队/团队可以有5-8名学生。



我可以使用select t.student,t1.student来自Prefrences_Table t inner join Prefrences_Table t1 on t.student = t1.preferences和t.preferences = t1.student和t.student< t1.student找到共同的偏好。



如何创建组号,然后将它们插入学生表中,检查最少5名和最多8名学生是否有此ID。 br />


将通过单击应用程序中的按钮来创建组



I am asking each student to give me maximum 7 names, who they want to team up with. then taking this information in account fulfill as many choices as possible and create a team.

These are the rules i have to follow to create teams.

First i will check if "Stud A" has added "Stud B" in his Preferences list, and "stud B" has also added "stud A" in his preference, if both of them have added each other i want to add them in group/team (Do this for all students). Second, Check for one sided preferences, "Stud A" has added "Stud B" in his Preferences but stud B hasn't, and add them in group. Third add all students without preference to random Groups. Each group/team can have 5-8 students.

I can use select t.student, t1.student from Prefrences_Table t inner join Prefrences_Table t1 on t.student = t1.preferences and t.preferences = t1.student and t.student < t1.student to find mutual preferences.

How do i create group numbers and than insert them in student table checking that minimum 5 and maximum 8 students have this id.

Groups are going to be created by clicking a button in the application

推荐答案


这篇关于检查sql server表中的列值,比较它们并插入不同的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:19