LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-06-2011, 09:33 AM   #1
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Oracle SQL - generating permutations of data between two tables.


Hi everyone,
Wondering if someone can help me with problem am I facing at work.
To keep it simple, I will just assume three tables (in reality there are more).

I have the following tables:

Employees
Jobs
Employee_Job_Ratings


So, the Employees table holds a list of employees, the Jobs table a list of Jobs and the Employee_Job_Ratings table holds a number which represents how "good" the employee is on a particular job.

I am trying to write a query which will determine how best to assign people to jobs within a team. Ie. what combination gives the best total utilization of skills. So, I could have three jobs and three people like this:

Code:
Job
A
B
C

Person
1
2
3


Ratings
A/1: 4
A/2: 2
A/3: 4
B/1: 3
B/2: 1
B/3: 2
C/1: 2
C/2: 3
C/3: 4

So - as you can see above, I could assign the people to jobs in the following permutations:

Code:
*1*
A - 1
B - 2
C - 3
Total: 9

*2*
A - 1
B - 3
C - 2
Total: 9

*3*
B - 1
C - 2
A - 3
Total: 10

*4*
B - 1
C - 3
A - 2
Total: 9

*5*
C - 1
A - 2
B - 3
Total: 7

*6*
C - 1
A - 3
B - 2
Total: 7

But - I obviously want the best people on each job. It would be silly for me to pick say 5 over 3 because the total score of competency for the whole team is 7 vs 10.


So what I am effectively looking to do is work out all the possible combinations that I can have people on each job, then I can do a SUM of their scores and effectively give a "score" for each combination. This will then allow us to see how best to distribute jobs within a team. Ie, do what I did above but automatically.

The above is a trivial example but in reality we have many teams with many jobs in each team. This is currently done manually however I know it can be done automatically - all the data is in our database so it would be excellent to be able to say to the users "this is your best strategy of job assignments", or at least give them an idea. The people in charge of this planning might not use what the system tells them but it allows them to at least get an idea.


I am fine with doing everything above, apart from getting the permutations into rows, ie, from tables A and B with three rows in each, getting the six possible combinations out. A cartesian join unfortunately doesn't do the job.

A person will only ever been assigned to a single job.


I know it's a tall ask and I apologise for not providing any code I have wrote myself, however it's unfortunately the very first step I'm stuck on - once I have that done then I will hopefully be fine! It's not as simple as just putting a person with a level 4 on one job because they might be a 3 on another whereas everyone else is a 1 and so they would be better used on that other job (ie on a level 3 job instead of a level 4).


Cheers,
 
Old 09-07-2011, 12:33 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Does something line the following help :- http://www.jlcomp.demon.co.uk/faq/Pe...mbination.html
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
export oracle tables as readable sql mjh Linux - Server 5 12-12-2007 03:27 AM
In Memory SQL type tables koodoo Programming 2 08-05-2006 03:55 AM
SQL: tables and queries in school project cold Programming 1 10-29-2005 07:58 PM
SQL: making queries from multiple tables ganninu Programming 1 01-08-2004 11:17 AM
SQL query, comparing tables ngomong Programming 3 07-07-2002 07:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration