Interview Answer

As soon as we started programming, we found to our surprise that it wasn’t as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs. Maurice Wilkes

Selecting ODD or EVEN rows from a table

April 12, 2016 7:26 pm

Comments



Selecting ODD or EVEN rows from a table



												desc suppliers;
												
												Name           Null     Type         
												-------------- -------- ------------ 
												EMPLOYEE_ID    NOT NULL NUMBER(6)    
												FIRST_NAME              VARCHAR2(20) 
												LAST_NAME      NOT NULL VARCHAR2(25) 
												EMAIL          NOT NULL VARCHAR2(25) 
												PHONE_NUMBER            VARCHAR2(20) 
												HIRE_DATE      NOT NULL DATE         
												JOB_ID         NOT NULL VARCHAR2(10) 
												SALARY                  NUMBER(8,2)  
												COMMISSION_PCT          NUMBER(2,2)  
												MANAGER_ID              NUMBER(6)    
												DEPARTMENT_ID           NUMBER(4)  

												

Solution

   					 
												-- select the odd rows using mod funcation
												select * from
												(select employee_id, first_name, last_name, salary, rownum rn
												from hr.employees
												order by employee_id)
												where  mod (rn, 2) <> 0;


												-- select the Even Rows using mod funcation
												select * from
												(select employee_id, first_name, last_name, salary, rownum rn
												from hr.employees
												order by employee_id)
												where  mod (rn, 2) = 0;
																    

Comments



Please login to add comments.