SQL Test3
SQL Test3
+----+-------+--------+--------------+--------------+
| Id | Name | Salary | DepartmentId | Joining Date |
+----+-------+--------+--------------+--------------+
| 1 | Joe | 70000 | 1 | 03/12/2015 |
| 2 | Henry | 80000 | 2 | 01/12/2015 |
| 3 | Sam | 60000 | 2 | 08/15/2017 |
| 4 | Max | 90000 | 1 | 02/01/2018 |
+----+-------+--------+--------------+--------------+
+----+----------+
| Id | Name |
+----+----------+
| 1 | IT_Global|
| 2 | Sales_NA |
| 3 | Others |
+----+----------+
Table: Manager
+----+-------+--------_--+
| Id | Name | ManagerId |
+----+-------+--------+--+
| 1 | Joe | 3 |
| 2 | Henry | 4 |
| 3 | Sam | NULL |
| 4 | Max | NULL |
+----+-------+--------+--+
Please write the SQL queries and sample output in the space given below.
Write a SQL query to find employees who have the highest salary in each of the departments. Please
also include their manager’s name
How many employees have joined from March 2015 to December 2015 and list by department name?
Write a SQL query.
Show number of employees by each department. The output should be readable to executives
without ‘_’. Write a SQL query.
Write a SQL query to list the employees with unique names and their department ID and Manager’s
ID.
| Id | Month | Salary |
|----|-------|--------|
| 1 | 1 | 6000 |
| 2 | 1 | 6500 |
| 1 | 2 | 3500 |
| 2 | 2 | 4500 |
| 3 | 2 | 5000 |
| 1 | 3 | 5000 |
| 3 | 3 | 5200 |
| 1 | 4 | 6000 |
| 3 | 4 | 7000 |
Write a SQL to get the cumulative sum of an employee's salary over a period of 3 months but
exclude the most recent month.
The result should be displayed by 'Id' ascending, and then by 'Month' descending.