DISPLAY EVEN or ODD NUMBER OF RECORDS

For Even row

Select * from (select rownum rn, e.* from emp e) Where mod (rn,2)=0;

For Odd row

Select * from (select rownum rn, e.* from emp e)

Where mod (rn,2)!=0;

Using Dense_rank()

   Even row

Select * from (
        Select dense_rank() over(order by empno)as rank ,e.* from emp e )
 Where mod(rank,2)=0;

output on tool

Retrieve even records from emp table

   Odd row

Select * from (
       Select dense_rank() over(order by empno)as rank ,e.* from emp e ) 
Where mod(rank,2)!=0;  

output on tool

display even or odd records
Retrieve odd records from emp table

  

Using decode

   Even row

Select * from emp
   Where empno in (
        Select decode (mod(rownum,2),0,empno,null )
From emp)

output on tool

display even or odd records using decode
Retrieve even records from emp table using decode
https://oraclesql.in/display-even-odd-number-of-rows/

Odd row

Select * from emp
    Where empno in (
         Select decode (mod(rownum,2),1,empno,null ) 
          From emp)                                                                                      

output on tool

display even or odd records using decode
Retrieve odd records from emp table using decode

Using case

  Even row

Select * from emp

                Where empno in

                   (select case mod(rownum,2)

                When 0 then empno

End

 From emp);

  odd row

Select * from emp

                Where empno in

                   (select case mod(rownum,2)

                When 1 then empno

End

 From emp);

Leave a Reply