Interview Answer

In software, we rarely have meaningful requirements. Even if we do, the only measure of success that matters is whether our solution solves the customerís shifting idea of what their problem is. Jeff Atwood

Implement IF-THEN-ELSE logic in a SELECT statement

April 12, 2016 7:26 pm

Comments



Implement IF-THEN-ELSE logic in a SELECT statement



												 desc HR.employees;
												 
												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)  

												

The following query display salary status based on the salary.


Solution

   					 
												SELECT first_name, last_name, CASE WHEN salary = 6000 THEN 'Minimum wage'
																   WHEN salary >= 24000 THEN 'Over paid'
																   ELSE 'Under paid'
															  END AS "Salary Status"
												FROM   hr.employees;
																    

Comments



Please login to add comments.