1

I have a table called PORTFOLIOS in which I have PORTFOLIO_ID, PORTFOLIO_NAME and SCORING_RULE columns. The SCORING_RULE column can have two different values (like double_scoring or single_scoring).

Now the requirement is I have to see what is the percentage of each scoring rule by combining all the records.

when I select the bunch of records from the table by limiting it with ROWNUM condition the result set should reflect the those percentages.

enter image description here

For example in the above table I have total 20 records in which 40% of records have double_scoring and 60% records have single_scoring as SCORING_RULE. So when I select first 10 records with below query then the result set must contain 4 double_scoring and 6 single_scoring records. How to ensure this kind result set. The database is oracle 10g.

SELECT * FROM PORTFOLIOS WHERE ROWNUM <=10

  • Select X records with scoring rule 1 union all Y records with rule 2. But your problem isn't really clear. There is no such thing as "first 10 records" unless you specify sorting criteria. Are you looking for random sets of records? – Mat Apr 11 '14 at 10:11
  • This may not be possible via simple select statement. – Raj Apr 11 '14 at 12:53
  • No, I am not looking for random sets of records. I am just limiting the result set with RWONUM condition in the where clause. This result set should contain the proportion of the SCORING_RULE percentages. I should not get all double_scoring records or single_scoring records or more double or single scoring records. The final result set should contain exactly matching with their percentages. – user1614862 Apr 11 '14 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.