Knowee
Questions
Features
Study Tools

Write a SQL query considering below schema. Create tables with Primary Key, foreign key constraints in given schemas.Manager (mid, eid, mname)Department (did, mid, dname, location)Employee (eid, ename, mobile, salary, joining_date, mid)i.Give the name and salary of employees whose salary are greater than each and every employees who are working under managerid 14.ii.Give the name of employees who have not assigned any department.iii.Give the employee names whose location is Kota.iv.Give the name of manager along with count of employees assigned to him/her in descending order

Question

Write a SQL query considering below schema. Create tables with Primary Key, foreign key constraints in given schemas.Manager (mid, eid, mname)Department (did, mid, dname, location)Employee (eid, ename, mobile, salary, joining_date, mid)i.Give the name and salary of employees whose salary are greater than each and every employees who are working under managerid 14.ii.Give the name of employees who have not assigned any department.iii.Give the employee names whose location is Kota.iv.Give the name of manager along with count of employees assigned to him/her in descending order

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

i. To get the name and salary of employees whose salary is greater than each and every employee working under managerid 14, you can use a subquery to first get the maximum salary of employees under managerid 14, and then compare this with the salary of all employees. Here is the SQL query:

SELECT ename, salary
FROM Employee
WHERE salary > (SELECT MAX(salary) FROM Employee WHERE mid = 14);

ii. To get the name of employees who have not been assigned any department, you can use a LEFT JOIN to join the Employee and Department tables on the manager id, and then filter for employees where the department id is null. Here is the SQL query:

SELECT E.ename
FROM Employee E
LEFT JOIN Department D ON E.mid = D.mid
WHERE D.did IS NULL;

iii. To get the employee names whose location is Kota, you can use a JOIN to join the Employee and Department tables on the manager id, and then filter for employees where the location is Kota. Here is the SQL query:

SELECT E.ename
FROM Employee E
JOIN Department D ON E.mid = D.mid
WHERE D.location = 'Kota';

iv. To get the name of the manager along with the count of employees assigned to him/her in descending order, you can use a GROUP BY clause to group by the manager name, and then order by the count of employees in descending order. Here is the SQL query:

SELECT M.mname, COUNT(E.eid) as employee_count
FROM Manager M
JOIN Employee E ON M.mid = E.mid
GROUP BY M.mname
ORDER BY employee_count DESC;

This problem has been solved

Similar Questions

Consider following schema and write query for given statementEmp (eid,ename,city,dname,salary) Project(eid,pid,pname,location)Create tables with Primary Key, foreign key constraints in given schemas.(1) Display name of employees who belongs to Computer department.(2) Display employee id whose name starts from letter J.(3) Display all details of employees whose salary is from 10000 to 20000.(4) Display name of employees who are having maximum salary.(5) Display name of employees whose salary is higher than average salary of the employee.(6) Display name of employees whose project id is 3 and location is Mumbai

The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.IdNameSalaryManagerId1Joe7000032Henry8000043Sam60000NULL4Max90000NULLGiven the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.EmployeeJoeOptionsselect e.Name as Employee to Employeefrom e inner join Employee has m on e.ManagerId = m.id where e.Salary > m.Salary;select e.Name as Employee from Employeeas e inner join Employee as m on e.ManagerId = m.idwhere e.Salary > m.Salary;select e.Name as Employeefrom Employee on e.ManagerId = m.id where e.Salary > m.Salary;select e.Name as Employee from Employeeas e inner join Employee

Write SQL QueriesEmployee TableDepartment Table1. Get the list of employees whose salary is more than 20K and are in HR department.2. Get the salary being paid to each Department.3. Get the employees with the third highest salary.4. Name and designation of the employees who don't have any manager

Find the following table EmployeeDetails, with the attributes EmployeeID, EmpName, Designation, Salary, DeptNo. You are assigned to a task of providing the solution to the operations department by writing the query which displays the employeeID and the Designation of all the employees whose Salaries are more than the Salary of employees designated as ManagerC

Write a query to display the ename of employees working in 'HR' department and who draw an annual salary greater than 1000000. [Consider employees who work in multiple departments too]. Display the records sorted in ascending order based on employee ename.Note:1. Display all the ename of employees working in 'HR' department and having annual salary greater than 1000000.2. Use Joins. Tables involved are employee, works and department3. Order by is mandatory.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.