简体   繁体   中英

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 (eg 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, eg:

SELECT *
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, eg:

SELECT *
FROM (
  SELECT *
  FROM   application_details
  ORDER BY total_marks DESC, subject_marks DESC
  )
WHERE ROWNUM <= 30;

(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, eg:

SELECT *
FROM   (
  SELECT DENSE_RANK()
         OVER (ORDER BY total_marks DESC,
                        subject_marks DESC) dr,
         ad.*
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM