Click here to Skip to main content
15,881,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Thanks in advance

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

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, 
 
Share this answer
 
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;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900