Home » RDBMS Server » Server Administration » Top N values
Top N values [message #370973] Thu, 27 July 2000 09:16 Go to next message
Jaro
Messages: 3
Registered: July 2000
Junior Member
I have Oracle 7.3
I need to make select 4 highest values from the table, but these values are to be obtained as sum.
Select ID, Name, sum(sal) from my_table
gropu by ID, name
And I need just 4 highest records. (using SQL, not PL/SQL)
Re: Top N values [message #370974 is a reply to message #370973] Thu, 27 July 2000 16:02 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
See the FAQ on SQL on this site
Re: Top N values [message #370982 is a reply to message #370973] Fri, 28 July 2000 12:37 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
If I understand the problem correctly, his should work fine:
1.) Create the query to return ID, Name, sum(sal)
2.) Query this result set to return just the top 4 records

Remember that a table and the result set from another query can be treated as being the same thing, see the following example:

Select My_Query.ID, My_Query.Name, My_Query.sum_sal
from
(select ID, Name, sum(Sal) sum_sal
from my_table
group by ID, name) My_Query
where ... rest of the top 4 syntax;

The My_Query alias is only there for clarity. Does this help.
Re: Top N values [message #371013 is a reply to message #370982] Tue, 08 August 2000 07:30 Go to previous message
Jaro
Messages: 3
Registered: July 2000
Junior Member
Could you write me the whole statement, bcause I dont know what to write to the where clause
Previous Topic: Re: Help on SQL "SELECT.."
Next Topic: string manipulation
Goto Forum:
  


Current Time: Thu Mar 28 18:42:29 CDT 2024