4cse-M2 En23cs3l1018

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Medi-Caps University

Department of Computer Science and Engineering


Database Management System (CS3CO39)

Enrollment No: EN23CS3L1018 Student Name: Saloni Vani


Evaluation Assignment

1. List full details of all employees

Query: select * from employees;

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;

3. Produce a report shown a list of monthly salaries of all employees. Round


Monthly Salary to 2 decimal places .The format of your report should be the
same as the table below.
Medi-Caps University
Department of Computer Science and Engineering
Database Management System (CS3CO39)

Enrollment No: EN23CS3L1018 Student Name: Saloni Vani


Nam Monthly Salary
e

-Note:
Arithmetic Operators. Use an arithmetic division operator in the SELECT clause
-Hint: use the Round function : ROUND(column_name, decimals)

select emp_name ,round(salary/12 ,2) as monthly_salary


FROM employee1;

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.

SELECT emp_name,salary ,round(salary *0.05,2)as bonus from employee1;

5. List the departments located in city Hiroshima or Toronto.

CREATE TABLE DEPARTMENTS1(DEPT_ID INT, LOCATION VARCHAR (20), DE-


PARTMENT_NAME VARCHAR(20));
INSERT INTO DEPARTMENTS1 (DEPT_ID , LOCATION , DEPARTMENT_NAME)
VALUES (101, 'hiroshima', 'finance')
INSERT INTO DEPARTMENTS1 (DEPT_ID , LOCATION , DEPARTMENT_NAME)
VALUES (102, 'toronto', 'hr')
INSERT INTO DEPARTMENTS1 (DEPT_ID , LOCATION , DEPARTMENT_NAME)
VALUES (103, 'india', 'it')
select * from departments1 where location in('hiroshima','toronto');
Medi-Caps University
Department of Computer Science and Engineering
Database Management System (CS3CO39)

Enrollment No: EN23CS3L1018 Student Name: Saloni Vani


6. Find employees whose last name ends with ‘son’.
select * from employees where last_name like '%son';

7. Find employees who has Not been assigned a manager.


select * from employees where manager_id is null;

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)

Enrollment No: EN23CS3L1018 Student Name: Saloni Vani

(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;

(13) What is Query to display first 5 Records from Employee table?


Select * from employees where rownum<=5;

(14) How to Display odd rows in Employee table?

select * from employees where mod(EMPLOYEE_ID ,2)=1;

(15) How to Display Even rows in Employee table?


select * from employees where mod(EMPLOYEE_ID ,2)=0;
Medi-Caps University
Department of Computer Science and Engineering
Database Management System (CS3CO39)

Enrollment No: EN23CS3L1018 Student Name: Saloni Vani

You might also like