15,958,244 members
See more:
I have a SQL query table where I need to return:

Salary_amount_1
Salary_amount_2
Salary_amount_3
Salary_amount_4

(not relevant below)
Salary_Date_1
Salary_Date_2
Salary_Date_3
Salary_Date_4

I've got 4 seperate columns for each salary amount to select into, but how do I specifically select the first salary for column 1, second for column two, third for three and fourth salary for column four?

What I have tried:

This is what I have (and isn't working for me yet)

min(details_Credit) as Salary_Amount_1,
max(details_Credit) as Salary_Amount_2,
Case
when details_Credit = min(details_Credit)
and details_Credit > min(details_Credit)
end Salary_Amount_3,
NULL as Salary_Amount_4,
Posted
Updated 27-Mar-18 14:04pm

## Solution 1

That's the weirdest sql query I think I've ever seen, but I think this is what you want, based on what you provided.

SQL
select min(details_Credit) as Salary_Amount_1,
max(details_Credit) as Salary_Amount_2,
details_Credit as Salary_Amount_3,
NULL as Salary_Amount_4,

## Solution 2

What specifies the salary amount? Based on what you have tried, there is some criteria to what defines the various types of salary base points.

If I had to guess, you are getting some syntax errors?

Have you tried
SELECT
MIN(details_Credit) as Salary_Amount_1,
MAX(details_Credit) as Salary_Amount_2,
CASE
WHEN details_Credit < MIN(details_Credit) and details_Credit > MIN(details_Credit) THEN
details_Credit
ELSE
NULL
END Salary_Amount_3,
NULL as Salary_Amount_4,
FROM table;