project 3
project 3
1. Write a query to join the employees table (Employee_id, Name, salary, Manager_id) with
the manager table(manager_id,name,city,salary), provided that the salary of employees
is greater than 50000 and there should be no null values.(The common column between
the two tables is manager_id)
Write your query here
SELECT e.Employee_id, e.Name AS Employee_Name, e.salary AS
Employee_Salary,
m.Manager_id, m.Name AS Manager_Name, m.City, m.salary AS
Manager_Salary
FROM employees e
JOIN manager m ON e.Manager_id = m.Manager_id
WHERE e.salary > 50000
4. From the SALESMEN and ORDERS tables write a SQL query to find all orders
generated by Bangalore-based salesmen. Return order_no, purchase_amt, order_date,
customer_id, salesman_id.
Write your query here
SELECT O.order_num, O.purchase_amt, O.date AS order_date,
O.customer_id, O.salesmen_id
FROM ORDERS O
JOIN SALESMEN S ON O.salesmen_id = S.salesmen_id
WHERE S.city = 'Bangalore';
5. We have 2 Employee tables from 2 different states write a query to combine the output
of each table.
Write your query here
Select emplooye_id ,name,city from table 1
Union
Select emplooye_id ,name,city from table 2
6. Write a query to get employee_id,name and salary of all the employees from the
employees table(employee_id, name, city,state, country,salary) where countries are
“india” and “US” using the UNION operator.
Write your query here
SELECT employee_id, salary FROM employees WHERE country = 'India'
UNION
SELECT employee_id, salary FROM employees WHERE country = 'US';
7. Write a query to display the maximum and minimum salaries of employees from the
Employees table(Employee_id, name,department,join_date,city, salary) hired 1 year
ago.
Write your query here
SELECT MAX(salary) AS max_salary, MIN(salary) AS min_salary
FROM Employees
WHERE join_date <= DATE_SUB(CURDATE(), INTERVAL 1 YEAR);
8. Write a query to display employees whose salary is greater than the average salary of
their department.
Write your query here
Select *
from Employees e WHERE e.salary > ( SELECT AVG(salary) FROM
Employees