0% found this document useful (0 votes)
5 views3 pages

Project 3

PROJECT 3

Uploaded by

rrjangra440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Project 3

PROJECT 3

Uploaded by

rrjangra440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Answer the given questions:

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

2. What will be the output of the following Query?


SELECT * from employees e LEFT JOIN manager m ON e.manager_id=m.manager_id
ORDER BY manager_id;
Write your answer here
SELECT * FROM employees e LEFT JOIN manager m ON e.manager_id =
m.manager_id ORDER BY e.manager_id;
3. From the SALESMEN (Salesmen_id,name,city,commission) and ORDERS
tables(order_num,purchase_amt,date,salesmen_id,customer_id)
write a SQL query to find all the orders issued by the salesman “John" Return order_no,
purchase_amt, order_date, customer_id, and 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.name = 'John';

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

9. From the EMPLOYEES table(Employee_id, name,department,join_date,city, salary),


create a view for those employees who belong to the city of Delhi.
Write your query here
SELECT Employee_id, name, department, salary
FROM Employees E
WHERE salary > (
SELECT AVG(salary)
FROM Employees
WHERE department = E.department

10. From the EMPLOYEES table(Employee_id, name,department,join_date,city, salary),


create an INDEX on employee_id column.
Write your query here
CREATE INDEX idx_employee_id
ON Employees(employee_id);

You might also like