Oracle SQL TUTORIAL – IF condition using CASE and DECODE - An Example

Опубликовано: 11 Октябрь 2024
на канале: Ganesh Anbarasu
8,286
52

In this video, we shall see how case and decode is used in real time scenario. SQL used in the video is given below.

SELECT * FROM emp_test ORDER BY gender;

count_of_employees Count_of_Male_Employees Count OF Female Employees --
15 5 8


select count(*) " Total Employees" from emp_test;


select gender,count(*) " Total Employees" from emp_test group by gender;


select sum(decode(gender,'M',1,0)) Count_OF_Male_Employees from emp_test;

select sum(case gender when 'F' then 1 else 0 end) as Count_OF_FeMale_Employees from emp_test;


SELECT count(*) " Total Employees" ,
sum(decode(gender,'M',1,0)) Count_OF_Male_Employees,
sum(case gender when 'F' then 1 else 0 end) Count_OF_Female_Employees
from emp_test;