How to create a merit list in descending order according some rules?

I am doing a project creating an admission system for a College. The technologies are Java and Oracle.

The College has 5 Branches across the country. The college invites Application Forms from Candidates Branch-wise but all data related to Candidates are stored and process Centrally from their Head office located in say, Delhi. There are 40% seats reserved for SC,ST,OBC,PH candidates etc and the central Head Office is responsible for creating a Branch-wise, Department-wise, category-wise merit list Order by their Total marks (for simplicity) in descending order to fill up the seats (say 30 seats for each Department). Now if the two Candidates secure the same marks then the candidate getting the higher mark in the subject applying for would be preferred. Now for simplicity, it is assumed that all required data are stored in a flat table say application_details{appl_no, form_no, branch, department, name, gender, dob, category, subject_marks, total_marks} .

Also, there will be a waiting list which will be 2 times the number of seats.

I am perplexed, as to how to deal with Ordering and comparing the whole lot of data (arround 50 thousand for all five Branches), using Oracle Procedure and functions.


This is just a SQL query you need, you probably won't need any procedural code (e.g. functions, procedures or java) to get the answers.

For example, given a set of applications with {appl_no, subject_marks, total_marks}, you can sort these in descending order of total_marks, and when some rows have identical total_marks, you can sort them in descending order of subject_marks, e.g.:

FROM   application_details
ORDER BY total_marks DESC, subject_marks DESC;

If you want to see who gets the 30 seats, you can limit the result to the first 30 results, e.g.:

  FROM   application_details
  ORDER BY total_marks DESC, subject_marks DESC

(This could also be done using the ROW_NUMBER analytic function.)

However, this doesn't deal with the unfairness of the algorithm in that if you have 30 seats, and 2 or more people tie for the 30th seat, you will pick one of them effectively at random and the other person will lose out.

An alternative is to change the rule such that up to 30 seats will be assigned; if there are any ties for the 30th seat, it is left vacant. To do this you could use a suitable analytic clause, e.g.:

FROM   (
         OVER (ORDER BY total_marks DESC,
                        subject_marks DESC) dr,
  FROM   application_details ad
WHERE dr <= 30;

This will return up to 30 top results, but if there is a tie for the 30th (or indeed 29th, or 28th, etc) place, it will not return a result.

Which one you use will depend on the rules you need to abide by.

One approach is using mainly java language, using an ORM tool like hibernate to map your table into an entity that implements the comparable interface. Then you can sort applications and save the results into another column of the same table or a new table that has a foreign key to your table.

Of course you could use pl/sql procedures, but that would be a code much more difficult to maintain, even if it would have better runtime performance.

Need Your Help

How to enable swipe to delete cell in a TableView?

ios uitableview uiswipegesturerecognizer

I have a UIViewController that implements TableViews delegate and datasource protocols.

Make a borderless form movable?

c# winforms border movable

Is there a way to make a form that has no border (FormBorderStyle is set to "none") movable when the mouse is clicked down on the form just as if there was a border?