Professional Documents
Culture Documents
DBMS Oel
DBMS Oel
Umar Hanif
BESE 28 C
use OpenEndedLabDBMS;
Name VARCHAR(100),
Age INT
);
CompanyID INT,
EmployeeID INT,
);
Employee Table
INSERT INTO OrganizationalPerformance (CompanyID, EmployeeID, PerformanceScore) VALUES
(1, 1, 85.5),
(1, 2, 92.3),
(1, 3, 78.9),
(2, 4, 88.7),
(2, 5, 91.2),
(1, 6, 84.2),
(1, 7, 89.6),
(2, 8, 77.3),
(2, 9, 90.1),
Result
Code for Tasks:
--Task 1
--Task 2
select case
when age < 30 then 'Under 30'
when age >= 30 and age <=40 then 'Between 30 and 40'
when age > 40 then 'Over 40' end as AgeGroup,count(*) as EmployeeCount from Employee
Result
--Task 3
Select
Case
Else 'Teen'
End As AgeGroup,
avg(OP.PerformanceScore) As AveragePerformanceInAgeGroup
From OrganizationalPerformance As OP
Where OP.CompanyID = 1
Group By
Case
Else 'Teen'
End;
Result:
--Task 4
end as AgeGroup,
case
Result:
Notes:
Task 1
⦁ Use of Select and From to get values from Employee table that is aliased as E
Task 2
⦁ Use of Select and From to get values from Employee table that is aliased as E.
⦁ Case Statement used to create a new column that specifies AgeGroup and then again to group
the output using the Case statement in Group By.
Task 3
⦁ Use of Select and From to get values from OrganizationalPerformance table that is aliased as E.
⦁ Use of Inner Join using EmployeeID to get values from Employee table that is aliased as E.
⦁ Case Statement used to create a new column that specifies AgeGroup and then again to group
the output using the Case statement in Group By.
Task 4
⦁ Use of Select and From to get values from OrganizationalPerformance table that is aliased as E.
⦁ Use of Inner Join using EmployeeID to get values from Employee table that is aliased as E.
⦁ Case Statement used to create a new column that specifies AgeGroup and then again to group
the output using the Case statement in Group By.
⦁ Multiple Avg() Function to get average Performance Score with a Case Statement to select
different companies average score.