SQL Assignment 1
SQL Assignment 1
Assignment # 1
A small IT firm designing business software for its clients wants to store and manage its
data. It has identified following entities for which, it will maintain data.
1. Clients
2. Employees
3. Departments
4. Projects
5. EmpProjectTasks *
The tables below describe attributes for each entity. Keep the table name same.
Clients
Attribute Name Attribute Type Constraint Remarks
Client_ID Integer Primary Key
Cname STRING(30) Not Null
Address STRING(30)
Email STRING(30) Unique
Phone STRING(10)
Business STRING(20) Not Null Business type of
client like
Manufacturer,
Reseller,
Consultant,
Professional etc.
Employees
Attribute Name Attribute Type Constraint Remarks
Empno Integer Primary Key
Ename STRING(20) Not Null
Job STRING(15)
Salary Decimal Must be positive Use CHECK constraint
to ensure salary is > 0
Deptno Integer Foreign Key Deptno as per
Departments table
Departments
Attribute Name Attribute Type Constraint Remarks
Deptno Integer Primary Key
Dname STRING(15) Not Null
Loc STRING(20)
Projects
Attribute Name Attribute Type Constraint Remarks
Project_ID Integer Primary Key
Descr STRING(30) Not Null Description of
project like
‘Accounting’ ,
‘Inventory’, ‘Payroll’
etc.
Start_Date DATE Start date of project
Planned_End_Date DATE Planned End date of
Project
Actual_End_date DATE Must be later than Actual End date of
Planned_End_Date project (Use CHECK
constraint)
Budget Decimal Must be positive Use CHECK constraint
to ensure budget is >
0
Client_ID INTEGER Foreign Key Client ID from Clients
Table
EmpProjectTasks
Attribute Name Attribute Type Constraint Remarks
Project_ID Integer Primary Key, Foreign Composite primary
Key
key and foreign keys
Empno INTEGER Primary Key, Foreign
Key referring Projects
and
Employees table
Start_Date DATE Start date when
employee begins
task
on this project
End_Date DATE End date when
employee finishes
task
on this project
Task STRING(25) Not Null Task performed
by employee
like designing,
coding,
review, testing etc.
Status STRING(15) Not Null Status of task like
‘in progress’,
‘complete’,’cancelled’
Clients
Client Cname AddresS Email Phone Business
ID
1001 ACME Utilities Noida [email protected] 95678800 Manufacturi
m 32 ng
1002 Trackon Mumbai [email protected] 87342100 Consultant
Consultants m 90
1003 MoneySaver Kolkata [email protected] 77998866 Reseller
Distributors om 55
1004 Lawful Corp Chennai [email protected] 92103422 Professional
19
Employees
Empno Ename Job Salary Dept No
Departments
Projects
1. Create the Clients table using the information provided above. Once tables are ready, fill in
the given data of this table.
2. Create the Departments table using the information provided above. Once tables are ready,
fill in the given data of this table.
3. Create the Employees table using the information provided above. Once tables are ready, fill
in the given data of this table.
4. Create the Projects table using the information provided above. Once tables are ready, fill in
the given data of this table.
5. Create the EmpProjectTasks table using the information provided above. Once tables are
ready, fill in the given data of this table.
6. Display customer details with business as ‘Consultant’.
7. Display employee details who are not ‘Developers’.
8. Display project details with budget > 100000.
9. Display details of project that are already finished.
10. Display employee names beginning with ‘M’.
11. Display employee names ending with ‘a’.
12. Display the task that is ‘In Progress’.
13. Display employee name and salary in descending order of salary.
14. Display tasks in ascending order of end date.
15. Display distinct jobs from Employees table.
16. Display employee name, salary and bonus calculated as 25% of salary.
17. Display the employee name and their corresponding department name.
18. Find the total number of employees in each department.
19. Calculate the average salary of employees for each job title.
20. Find the total budget allocated for all projects combined.
21. Count how many projects have been completed for each client.
22. Find the maximum salary for employees in the Development department.
23. List all the projects along with the names of the clients using a join between Projects and
Clients tables.
24. Show all the employees and their corresponding project descriptions where the project
status is 'In Progress'.
25. List all the employees along with their department names and the projects they have been
assigned to.
26. List the employees who worked on more than one project using a HAVING clause.