Here is an example:
Table
Name | Salary |
---|---|
A | 1000 |
B | 500 |
C | 400 |
D | 100 |
Output
Name | salary_highest | name | salary_Lowest |
---|---|---|---|
A | 1000 | D | 100 |
B | 500 | C | 400 |
So the highest and lowest salary should be mapped and come in a single row and the output should be a multiple rows not a single row that maps the high-low salaries until the table’s data ends.
I am able to get max and min, second max and second min and so on and only single row at a time but that is not what I want.
Any loops we can use. I am using MySQL - mycompiler.io online compiler.
Update: I tried this way -
Select E1.salary as MIN, E2.salary as MAX
from employees E1, employees E2 where
E1.salary < (select max(salary) from employees) and
E2.salary < (select min(salary) from employees);
And got this output-
Output
MIN | MAX |
---|---|
500 | 1000 |
400 | 1000 |
100 | 1000 |
500 | 500 |
400 | 500 |
100 | 500 |
500 | 400 |
400 | 400 |
100 | 400 |
Guess the looping works but all the extra recs gotta go, output should be-
MIN | MAX |
---|---|
100 | 1000 |
400 | 500 |
which are present in the list. Where am I wrong here