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 |
|
Erad
Starting Member
4 Posts |
Posted - 2009-07-21 : 02:31:12
|
| Hey all,I have a table that has many fields, but 4 important 'int' ones. For simplicity's sake, we'll call them 1, 2, 3, and 4. I need a query that will take 10 rows, in order of descending sums of these 4 fields. For the result of the query, all I need is a field called 'name' and the actual sum of 1, 2, 3, and 4 for that row. |
|
|
Erad
Starting Member
4 Posts |
Posted - 2009-07-21 : 02:33:51
|
| I forgot to mention that my first attempt was:SELECT *FROM `table`ORDER BY SUM(1+2+3+4)LIMIT 10but this didn't work |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-21 : 02:38:22
|
| are you looking for this....SELECT TOP 10*FROM `table`ORDER BY (1+2+3+4) descMangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
Erad
Starting Member
4 Posts |
Posted - 2009-07-21 : 03:00:03
|
quote: Originally posted by Mangal Pardeshi are you looking for this....SELECT TOP 10*FROM `table`ORDER BY (1+2+3+4) descMangal Pardeshihttp://mangalpardeshi.blogspot.com
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '10* FROM `table` ORDER BY (1+2+3+4) desc LIMIT 0, 30' at line 1Close... |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-21 : 03:05:56
|
| Ahh... These are the forums for SQL Server.You need to ask MySQL related questions on MySQL forums.Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
Erad
Starting Member
4 Posts |
Posted - 2009-07-21 : 03:10:16
|
My apologies, thanks for the help anyways |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-21 : 03:12:22
|
| http://forums.mysql.com/Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
|
|
|
|
|