Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 difference between the highest and lowest salaries

Author  Topic 

Maple50175
Starting Member

6 Posts

Posted - 2007-05-08 : 10:35:28
I need to display the difference between the highest and lowest salaries. Label the column DIFFERENCE. like below:


From what I came up with is should look something like so:

<b>SQL> select * from 'salary' order by salary desc limit
select * from 'salary' order by salary desc limit 1,1 </b>

DIFFERENCE
------------------
4200

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-08 : 10:38:35
MySQL queries are not answered here. There are better forums for that.

Anyhow, the basic idea is

SELECT MAX(Salary) - MIN(Salary) AS Difference
FROM Salary


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-08 : 10:47:54
Doesn't MySQL have MAX and MIN aggregate functions?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Maple50175
Starting Member

6 Posts

Posted - 2007-05-08 : 10:48:53
yes they do have max and min functions..
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-08 : 10:53:30
Homework question, no doubt!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Maple50175
Starting Member

6 Posts

Posted - 2007-05-08 : 10:56:45
for somereason it's not working..
Im typing:

select max(sal) - min(sal) as difference
from sal;

And it's saying invald table

How can I see the names of all tables in the database?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-08 : 10:58:30
1. sp_tables
2. select * from information_schema.tables

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Maple50175
Starting Member

6 Posts

Posted - 2007-05-08 : 11:08:14
got it its like this:

select max(sal)-min(sal) DIFFERENCE from emp;


that worked

or if you want to not be technical you can do this:

SQL> select 4200 difference from dual;



Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-08 : 11:13:13
Is difference - 4200, universally applicable difference between max and min salary?

And there is no dual table in SQL Server.

Why don't you read the SQL Server help, it seems natural way, isn't it?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -