Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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)
--------------------------
    |student | Group ID/Name |
    --------------------------
    Stud A   |    
    Stud B   |  
    Stud C   |  
    Stud D   |  
    Stud E   |  
    Stud F   |  
    --------------------------


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
Posted
Updated 7-Oct-13 10:15am
v3

1 solution

You need to create a set of rules as to how you will create groups (you need some sort of priority for the guaranteed overlaps of group members).

You can create a VIEW giving the count of selections for each students and (perhaps) order by count, descending, giving you a list to start from. You can take this further by making the view the result of an INNER JOIN that links students who select one another (but that will omit those not part of the group - so think UNION to get those on the list, too).

Now, you create a table linking students and a group number or name (something I guess you don't yet have defined).

When you create a group, you can use it in a SUBQUERY to remove references to those students from your VIEW (the subquery should, obviously, be part of your view). You are using the subquery to remove students already in groups.

When you run out of large-enough groups, you'll need a rule for using members of too-small groups and singletons.

Having a rule-set, however, is essential: you need some sort of clarity in how to start making your groups and how to handle conflicts and other exceptions.


 
Share this answer
 
Comments
Mubshir 7-Oct-13 16:16pm    
I have edited the question to make it more clear, thanks for the reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900