rownum query [message #631432] |
Wed, 14 January 2015 01:15 |
|
sss111ind
Messages: 634 Registered: April 2012 Location: India
|
Senior Member |
|
|
HI ALL,
I WANT TO FETCH 10 ROWS BUT GIVING PRIORITY TO ALL THE JOB.
PLESE HELP ON THIS.
SELECT * FROM (SELECT E.*,ROW_NUMBER() OVER (PARTITION BY JOB ORDER BY ENAME )RN FROM EMP E)
WHERE ROWNUM<=10 AND RN <= 2 ;
REGARDS,
Nathan
[Updated on: Wed, 14 January 2015 01:16] Report message to a moderator
|
|
|
|
|
|
|
Re: rownum query [message #631448 is a reply to message #631438] |
Wed, 14 January 2015 02:04 |
|
sss111ind
Messages: 634 Registered: April 2012 Location: India
|
Senior Member |
|
|
Sorry Michel,I never meant this.
Actually i want to pick 2 records(rn) from each job amongst 10 rows(rownum). If anything less rows if it fetches then it should pick extra rows to make it 10.
first_time second_time total
ANALYST 2 2
CLERK 2 1 1
MANAGER 2 2
PRESIDENT 1 1
SALESMAN 2 2
total 9 1 10
[Updated on: Wed, 14 January 2015 02:05] Report message to a moderator
|
|
|
|
|
Re: rownum query [message #631453 is a reply to message #631448] |
Wed, 14 January 2015 02:16 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
sss111ind wrote on Wed, 14 January 2015 13:34
first_time second_time total
CLERK 2 1 1
Why is the total 1? Please show your input and expected output, and explain the rules to get the expected output.
|
|
|
|
Re: rownum query [message #631456 is a reply to message #631455] |
Wed, 14 January 2015 02:22 |
|
sss111ind
Messages: 634 Registered: April 2012 Location: India
|
Senior Member |
|
|
Thank you very much Michel, before I clarified my question you have delivered the answer already. Yes that was a mistake.
My clarification as follows
In the first query two where clauses are there
1.Where rn<=2 (to pick 2 rows of each job )
2.Where rownum<=10( to pick 10 rows)
But the above query gives 9 rows means ,1 extra should be picked in point1 to make it 10 in point 2.
And first_time and second_time is search operation of oracle not output of the query.
Regards,
Nathan
[Updated on: Wed, 14 January 2015 02:23] Report message to a moderator
|
|
|