Display Odd/ Even number of records

Showing Answers 1 - 13 of 13 Answers

Vijay

  • Aug 10th, 2005
 

Odd number of records:  
select * from emp where (rowid,1) in (select rowid, mod(rownum,2) from emp);  
1  
3  
5  
Even number of records:  
select * from emp where (rowid,0) in (select rowid, mod(rownum,2) from emp)  
2  
4  
6  

  Was this answer useful?  Yes

Murali

  • Jan 21st, 2007
 

HI ,

Select rownum,empno,ename,salary from emp group  by rownum,empno,ename,salary having Mod(rownum,2)=0   --  Todisplay EVEN records.

Select rownum,empno,ename,salary from emp group  by rownum,empno,ename,salary having Mod(rownum,2)=1  --   Todisplay ODD records.  

Note : Here u should group all the columns those are in select statement. Here it is rownum,empno,ename,salary etc.

Please feel free to for any queiries

Thanks,

Murali.

 

  Was this answer useful?  Yes

To display the odd/even number of records we can use:

Even:
select * from table_name where (rowid,0) in
(select rowid,mod(rownum,2) from table_name);

Odd:
select * from table_name where (rowid,1) in
(select rowid,mod(rownum,2) from table_name);

We can use the below query to get the odd record of the table  --

select r from
(
SELECT rownum r FROM EMP
)

where mod(r,2) != 0

We can use the below query to get the even record of the table  --

select r from
(
SELECT rownum r FROM EMP
)

where mod(r,2) = 0

  Was this answer useful?  Yes

sharmasl

  • Mar 23rd, 2009
 

These are the querys:-

FOR Odd number of records:

select * from emp where (rowid ,1) in (select rowid, mod(rownum,2) from emp);

 

FOR Even number of records:
select * from emp where (rowid ,0) in (select rowid, mod(rownum, 2) from emp);

try.........................

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions