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.
| 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 limitselect * 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 DifferenceFROM SalaryPeter LarssonHelsingborg, Sweden |
 |
|
|
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 AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Maple50175
Starting Member
6 Posts |
Posted - 2007-05-08 : 10:48:53
|
| yes they do have max and min functions.. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-05-08 : 10:53:30
|
| Homework question, no doubt!Peter LarssonHelsingborg, Sweden |
 |
|
|
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 differencefrom sal;And it's saying invald tableHow can I see the names of all tables in the database? |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-05-08 : 10:58:30
|
| 1. sp_tables2. select * from information_schema.tablesHarsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
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 workedor if you want to not be technical you can do this:SQL> select 4200 difference from dual; |
 |
|
|
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 AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|