Task
Task
1. Write a SQL query to create a table named "Employees" with columns: "EmployeeID"
(integer, primary key), "FirstName" (text), "LastName" (text), "Salary" (decimal), and
"DepartmentID" (integer).
2. Write a SQL query to insert a new record into the "Employees" table with values:
EmployeeID = 401, FirstName = 'Bob', LastName = 'Taylor', Salary = 75000,
DepartmentID = 10.
4. Write a SQL query to insert multiple rows into the "Departments" table in a single
query.
5. Write a SQL query to create a table "Projects" with fields: "ProjectID" (integer),
"ProjectName" (text), and "Budget" (decimal), ensuring "ProjectID" is unique.
6. Write a SQL query to delete all employees from the "Employees" table who earn less
than 40000.
8. Write a SQL query to remove the "Departments" table from the database.
9. Write a SQL query to change the "Location" of the "IT" department to 'Building B'.
10. Write a SQL query to delete records from the "Projects" table where the Budget is
NULL or 0.
11. Write a SQL query to select all columns from "Employees" where the last name starts
with 'S' and ends with 'n'.
12. Write a SQL query to select "FirstName", "LastName", and "Salary" from "Employees"
and sort by "Salary" in ascending order.
13. Write a SQL query to retrieve employees whose salary is between 60000 and 90000.
15. Write a SQL query to select all employees who do not belong to any department (i.e.,
DepartmentID is NULL).
18. Write a SQL query to find the average salary of employees grouped by DepartmentID.
19. Write a SQL query to find the maximum and minimum salary in the "Employees" table.
20. Write a SQL query to find departments having more than 5 employees using GROUP
BY and HAVING.
21. Write a SQL query to display the full names of employees along with their department
names using a JOIN.
22. Write a SQL query to list the names of employees who are assigned to projects with
budgets over 1,000,000.
23. Write a SQL query using a subquery to find employees who earn more than the
average salary of all employees.
24. Write a SQL query using a JOIN to find departments that have no employees assigned.
25. Write a SQL query to list all employees along with project details using LEFT JOIN
(even if the employee isn’t assigned to a project).
26. Write a SQL query to create a new view named "HighSalaryEmployees" that shows all
employees with salary greater than 100000.
27. Write a SQL query to list the second highest salary from the "Employees" table.
28. Write a SQL query to add a new column named "Bonus" (decimal) to the "Employees"
table and update it as 10% of the Salary.
29. Write a SQL query to select the department with the highest average salary.
30. Write a SQL query to find employees whose names contain exactly 5 letters and end
with 'n'.