0% found this document useful (0 votes)
13 views

SQL Programme Lab Record

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SQL Programme Lab Record

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

SQL PROGRAMS
Create the following tables in database
TABLE NAME : EMPLOYEES

CREATE TABLE Employees


(EmployeeID INT PRIMARY KEY,FirstName VARCHAR(255),
LastName VARCHAR(255),Department VARCHAR(50),
Salary INT,Doj Date);

TABLE NAME : EMPLOYEESTASKS

CREATE TABLE EmployeeTasks (TaskID INT PRIMARY KEY,


TaskName VARCHAR(255),TaskDescription TEXT,
EmployeeID INT,TaskDueDate DATE);
a)
1) Retrieve employees and their respective department along with the total
number of employees in each department:

SELECT department, COUNT(*) AS employee_count


FROM employees
GROUP BY department;

b)

c)
d)
2) Retrieve the count of employees in each department and their average salary:

SELECT department, COUNT(*) AS employee_count,


AVG(salary) AS average_salary
FROM employees
GROUP BY department;

e)
f)
3) Retrieve the employee with the highest salary:

SELECT * FROM employees ORDER BY salary DESC LIMIT 1;

g)
4) Retrieve all tasks along with their assigned employees:
SELECT et.taskname, e.firstname, e.lastname
FROM employeetasks et
JOIN employees e
ON et.employeeid = e.employeeid;

h)
i)

5) Retrieve unique task names:

SELECT DISTINCT taskname FROM employeetasks;

j)
k)
6) Retrieve tasks with due dates between two specific dates
(e.g., '2023-01-01' and '2023-02-01'):

SELECT * FROM employeetasks


WHERE taskduedate BETWEEN '2023-01-01' AND '2023-02-01';

l)
7) Retrieve tasks due before a specific date (e.g., '2023-01-01'):

SELECT * FROM employeetasks WHERE taskduedate < '2023-04-01';

m)
8) Count the number of tasks for each employee:

SELECT employeeid, COUNT(*) AS task_count


FROM employeetasks GROUP BY employeeid;
n)
9) Retrieve the task with the earliest due date:

SELECT TaskName,TaskDueDate,EmployeeId FROM employeetasks;

o)

p)
10) Count the number of tasks for each department:

SELECT e.department, COUNT(et.taskid) AS task_count


FROM employees e
LEFT JOIN employeetasks et
ON e.employeeid = et.employeeid
GROUP BY e.department;
q)
r)

11) Retrieve tasks and the corresponding department of the assigned employee:

SELECT TaskName,TaskDueDate,et.EmployeeId, e.department


FROM employeetasks et
JOIN employees e ON et.employeeid = e.employeeid;
s)

t)
12) Retrieve tasks with descriptions containing a specific keyword (e.g., research):

SELECT * FROM employeetasks


WHERE taskdescription LIKE '%research%';

u)
13) Retrieve details of all the employees whose name ends with ‘a’ or ‘e’
select * from employees where firstname like '%e' or firstname like '%a';

14) Retrieve employeetask details of task id 5,8,10


select * from employeetasks where taskid in (5,8,10);

15) Retrieve Department wise average salary


select department,avg(salary) as Department_Payroll
from employees group by department;

You might also like