Ict Lab 5
Ict Lab 5
QUERY 1:
Write a query to select all employees’ first names and last names
from the employee table.
COMMENTS:
In This query we selected first and last names from tables by
using SELECT and FROM commands.
OUTPUT:
QUERY 2:
Retrieve all employees who work in the department with an ID of
90.
COMMENTS:
Here we displayed all employees having department id 90 by
using SELECT FROM and WHERE commands.
OUTPUT:
QUERY 3:
Find all employees whose salary is greater than $6000 but less
than $48000.
COMMENTS:
In this query we found all the employees having salary greater
than 6000$ and less than 48000$ by using SELECT,FROM,AND
and WHERE commands.
OUTPUT:
QUERY 4:
Change the salary of the employee with the last name 'Smith' to
$40,000.
COMMENTS:
In this query we changed the salary of employee having last
name Smith to $40000 by using UPDATE,SET and WHERE
commands.
OUTPUT:
QUERY 5:
Insert a new department into the department table with
appropriate details (department name and department ID).
COMMENTS:
In this query we added a new department into department table
by first using the INSERT INTO command to direct the path and
then using VALUES command to input their details.
OUTPUT:
QUERY 6:
Delete the employee record where the employee ID is 110.
COMMENTS:
In this query we deleted the employee record having an employee
id 110 by using DELETE and WHERE commands.
OUTPUT:
Q
UERY 7:
QUERY 8:
Write a query to group employees by their department and show
the total number of employees in each department.
COMMENTS:
In this query first we used SELECT command to select department
id then we used COUNT command to count the number of
employees id from employees table same and then used GROUP
BY command to group the results by department id to calculate
the number of employees.
OUTPUT:
QUERY 9:
Retrieve a list of distinct job titles from the employee table.
COMMENTS:
In this query first we used DISTINCT command to only show only
distinct job titles from employee’s table.
OUTPUT:
QUERY 10:
Write a query to calculate the average salary for each job id .
COMMENTS:
In this query first we used SELECT command to select job id then
we used AVG command to calculate the average salary from the
employees table and then we used GROUP BY command to group
the results by job id to calculate the average salary.
OUTPUT:
QUERY 11:
Write a query to find all employees whose salary is below
24000 and department id is 90.
COMMENTS:
In this query first we used SELECT FROM WHERE, and AND
command to find all the employees having salary below 24000
and employee id 90.
OUTPUT:
QUERY 12:
Write a query to calculate the average salary of employees in
each department, showing both the department name and the
average salary.
COMMENTS:
In this query first we used SELECT command to select the
department name then we used AVG command to calculate the
average salary from the employees table then we used then we
used JOIN command to join employees and department tables
where department id are same then we used GROUP BY command
to group the results by department name to calculate the average
salary for every department.
OUTPUT: