/*
A company wants to divide the employees into teams such that all the member on each team have the salary.
The teams should follow thses criteria:
a) Each team should consist of at least two employees.
b) All the employees on a team should have the same salary
c) If the salary of an employee is unique, we do not assign this employee to any team.
*/

-- Schema Setup
create table company(
emp_id int,
name varchar(20),
salary int
);

insert into company values(2,'Meir', 3000),
(3, 'Michael',3000),
(7, 'Addilyn', 7400),
(8, 'Juan', 6100),
(9, 'Kannon', 7400);

-- Solution
SELECT
   CONCAT('Team','',DENSE_RANK() OVER(ORDER BY salary DESC)) AS Teams,
   name,
   salary
FROM company
WHERE salary IN (SELECT salary FROM company GROUP BY salary HAVING COUNT(salary) >= 2);

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: