SQL Assignment
SQL Assignment
SQL Assignment
Consider the tables given below and answer the questions that follow:
Table: Department
Table: Employee
1. Create the above tables where Dept is the Primary Key of Department while
foreign key of Employee. No is the Primary Key of Employee. Also write the
queries to insert tuples in them.
2. Display the details of all the employees.
3. Display the Salary, Zone, and Grade of all the employees.
4. Display the records of all the employees along with their annual salaries. The
Salary column of the table contains monthly salaries of the employees.
5. Display the records of all the employees along with their annual salaries. The
Salary column of the table contains monthly salaries of the employees. The
new column should be given the name “Annual Salary”.
6. Display the details of all the employees who are below 30 years of age.
7. Display the names of all the employees working in North zone.
8. Display the salaries of all the employees of department 10.
9. Display the details of all the employees whose Grade is NULL.
10. Display the details of all the employees whose Grade is not NULL.
11. Display the names of various zones from the table Employee. A zone name
should appear only once.
12. Display the various department numbers from the table Employee. A department
number should be displayed only once.
13. Display the details of all the employees of department 10 who are above 30 years
of age.
14. Display the details of all the employees who are getting a salary of more than
35000 in the department 30.
15. Display the names and salaries of all the employees who are working neither in
West zone nor in Centre zone.
16. Display the names of all the employees who are working in department 20 or 30.
17. Display the details of all the employees whose salary is between 32000 and
38000.
18. Display the details of all the employees whose grade is between „A‟ and „C‟.
19. Display the names of all the employees who are working in department 20 or 30.
(Using IN operator)
20. Display the names and salaries of all the employees who are working neither in
West zone nor in Centre zone. (Using IN operator)
21. Display the details of all the employees whose salary is between
32000 and 38000. (Using BETWEEN operator)
22. Display the details of all the employees whose grade is
between „A‟ and „C‟. (Using BETWEEN operator)
23. Display the name, salary, and age of all the employees whose names start with
„M‟.
24. Display the name, salary, and age of all the employees whose names end with „a‟.
25. Display the name, salary, and age of all the employees whose names contain „a‟
26. Display the name, salary, and age of all the employees whose names do not
contain „a‟
27. Display the details of all the employees whose names contain „a‟ as the second
character.
28. Display the sum and average of the salaries of all the employees.
29. Display the highest and the lowest salaries being paid in department 10.
30. Display the number of employees working in department 10.
31. Display the details of all the employees in the ascending order of their salaries.
32. Display the details of all the employees in the descending order of their names.
33. Display the details of all the employees in the ascending order of their grades
and within grades in the descending order of their salaries.
34. Display the total number of employees in each department.
35. Display the highest salary, lowest salary, and average salary of each zone.
36. Display the average age of employees in each department only for those
departments in which average age is more than 30.
37. Assign grade B for all those employees whose grade is NULL.
38. Increase the salary of all the employees above 30 years of age by 10%.
39. Modify the zone of Moksh to North and age to 30.
40. Give an increment of 200 to all the employees.
41. Delete the records of all the employees whose grade is C and salary is below
30000.
42. Delete the records of all the employees of department 10 who are above 40 years
of age.
43. Add another column HireDate of type Date in the Employee table.
44. Delete the column age from employee.
45. Change the attribute name of salary to salary drawn
47. Display the details of all the employees who work in Sales department.
48. Display the Name and Department Name of all the employees
49. Count the number of employees in each department
50. Display the names of those employees whose salary does not lie within the range
of salary for their corresponding department.
51. Display the name of HODs along with the departments‟ name.
52. Drop the tables Employee and Department.