0% found this document useful (0 votes)
14 views

SQL assignemnt 3

Uploaded by

yash sontakke
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL assignemnt 3

Uploaded by

yash sontakke
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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,e.salary,e.manager_id,m.manager_id,m.name,m.city,m.salary
from employee as e
Join manager as m on e.manager_id=m.manager_id
Where salary > 50000
And e.manager_id is not null
And m.manager_id is not null;

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 e.* from employee as e
Left join manager m on e.manager_id =m.manager_id
Order by 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_no,o.purchase_amt,o.order_date,o.customer_id,o.salesman_id from
orders as o
Join salesmens as s on o.salesmen_id = s.salesmen_id
Where name =”jhon”;

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_id,o.purchase_amt,o.order_date,o.customer_id, o.salesman_id
From orders as o join salesmen as s
On o.salesmen_id = s.salesmen_id
Where city = banglore;

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 * from employee_table1
Union
Select* from employee_table2;
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,name,salary from employees
Where country = “india”
Union
Select employee_id,name,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 emplyees
Where joinin_date>=date_sub(curdate(),intervel 1year);

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 salary > (select avg(salary) from employees where department=e.department);

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,join_date,city,salary from employees
Where city = “Delhi”;

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 employee_id_index on employees(employee_id);

You might also like