DBMS 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

DBMS LAB-2

2.1 Query to display the Employee Name and Salary of all the employees earning more than

$2850.

Ans:

To query and display the Employee Name and Salary of all employees earning more than $2850, you would
typically use the following SQL query:

SELECT Employee_Name, Salary

FROM Employees

WHERE Salary > 2850;

In this query output:

 Employee_Name is the column that holds the name of the employees.


 Salary is the column that holds the salary of the employees.
 Employees is the table where the employee data is stored.

2.2 Query to display Employee Name and Department Number for the Employee No= 7900.

Ans:

To query and display the Employee Name and Department Number for the employee with Employee_No =
7900, you would use the following SQL query:

SELECT Employee_Name, Department_No


FROM Employees
WHERE Employee_No = 7900;

In this query:

 Employee_Name refers to the column that holds the employee's name.


 Department_No refers to the column that holds the department number.
 Employees is the table containing employee data.

2.3 Query to display Employee Name and Salary for all employees whose salary is not in the

range of $1500 and $2850.

Ans:

To display the Employee Name and Salary for all employees whose salary is not in the range of $1500 and $2850,
you can use the following SQL query:

SELECT Employee_Name, Salary


FROM Employees

WHERE Salary NOT BETWEEN 1500 AND 2850;

In this query output:

 Employee_Name is the column holding the employee names.


 Salary is the column for the employee salaries.
 The NOT BETWEEN condition ensures that salaries outside the range of $1500 to $2850 are selected.

2.4 Query to display Employee Name and Department No. of all the employees in Dept 10 and

Dept 30 in the alphabetical order by name.

Ans:

To display the Employee Name and Department No. of all employees in Dept 10 and Dept 30, and to order the
result alphabetically by employee name, use the following SQL query:

SELECT Employee_Name, Department_No

FROM Employees

WHERE Department_No IN (10, 30)

ORDER BY Employee_Name ASC;

OUTPUT:

 Employee_Name refers to the employee name column.


 Department_No refers to the department number column.
 The IN clause filters employees from Department 10 and Department 30.
 ORDER BY Employee_Name ASC ensures the results are sorted alphabetically by the employee name
in ascending order.

2.5 Query to display Name and Hire Date of every Employee who was hired in 1981.

Ans:

To display the Name and Hire Date of every employee who was hired in 1981, you can use the following SQL query:

SELECT Employee_Name, Hire_Date

FROM Employees

WHERE YEAR(Hire_Date) = 1981;

Explanation output:

 Employee_Name is the column holding the employee names.


 Hire_Date is the column containing the hire dates of employees.
 YEAR(Hire_Date) = 1981 filters out employees who were hired in the year 1981.
If your database system does not support the YEAR() function, you can modify the query as follows:

SELECT Employee_Name, Hire_Date

FROM Employees

WHERE Hire_Date BETWEEN '1981-01-01' AND '1981-12-31';

This version uses the BETWEEN clause to filter hire dates within the year 1981.

You might also like