Professional Documents
Culture Documents
4cse-M2 En23cs3l1018
4cse-M2 En23cs3l1018
4cse-M2 En23cs3l1018
2. Find employees who are older than 40 and have salary more than 20000. The
query result should display “EmpName”,“Age”, and “Salary” columns.Sort the
results in descending order by Age.
Query:
create table employee1 (emp_age int ,emp_name varchar (20) , salary int );
insert into employee1 (emp_age , emp_name , salary ) values ( 25,'sumit, 25000);
insert into employee1 (emp_age , emp_name , salary ) values ( 41,'raghav', 26000);
insert into employee1 (emp_age , emp_name , salary ) values ( 25,'abhishek', 27000);
insert into employee1 (emp_age , emp_name , salary ) values ( 25,'bedant', 25000);
insert into employee1 (emp_age , emp_name , salary ) values ( 42,'vedant', 25000);
select * from employee1;
select emp_name, emp_age ,salary from employee1 where emp_age>40 and salary >20000
order by emp_age desc;
-Note:
Arithmetic Operators. Use an arithmetic division operator in the SELECT clause
-Hint: use the Round function : ROUND(column_name, decimals)
4. The company wants to give year -end bonus to its employees. The bonus each
employee will get is the 5% of employee salary. Write a query to calculate the
bonus each employee will receive at the end of this year. This newly calculated
column should be named as “Bonus”. The query result should display
“EmpID”, “EmpName”, “Salary”, and “Bonus” columns.
8. Find the total number of departments . Your query should return the calcu-
lated field and name it as “Total Number of Departments”
select count(*) as total of departments from departments;
9. List the average salary of the employees in each department. Round Average
Salary to 2 decimal places.
10. Find the number of employees who earn less than the average salary.
select count(*) as num_employees from employees where salary <(select avg(salary) from
employees);
(11) What is the Query to fetch first record from Employees table?
Select * from employees where rownum=1;
Medi-Caps University
Department of Computer Science and Engineering
Database Management System (CS3CO39)
(12) What is the Query to fetch last record from the table?
SELECT *
FROM ( SELECT * FROM EMPLOYEES ORDER BY EMPLOYEE_ID DESC )
WHERE ROWNUM = 1;