SQL-tutorial
SQL-tutorial copied to clipboard
Basic to advance question part 1
Question:
Create a database named CompanyDB and add the following tables:
-
DepartmentsDepartmentID- INT, Primary KeyDepartmentName- VARCHAR(100)
-
EmployeesEmployeeID- INT, Primary KeyFirstName- VARCHAR(50)LastName- VARCHAR(50)Age- INTSalary- DECIMAL(10, 2)DepartmentID- INT, Foreign Key referencingDepartments(DepartmentID)JoiningDate- DATE
Insert at least 3 records into the Departments table and at least 10 records into the Employees table with different details.
Tasks:
- Write a query to display all employees along with their department names.
- Write a query to calculate the average salary of employees in each department.
- Write a query to display all employees who have joined in the last 2 years.
- Write a query to find the department with the highest number of employees.
- Update the salary of employees whose age is greater than 40 by increasing it by 10%.
- Write a query to delete all employees from the department named 'Sales'.
- Create a view named
HighEarnerEmployeesthat displays theEmployeeID,FirstName,LastName, andSalaryof employees earning more than100000. - Write a query using a common table expression (CTE) to find employees who report to the same department and have salaries greater than the average salary of that department.
https://github.com/developology/SQL_PART1.git
https://github.com/amrita-prog/Billing-Stock-System/blob/main/amritasql.txt