Home » SQL & PL/SQL » SQL & PL/SQL » Top three records
Top three records [message #3041] Sun, 01 September 2002 23:27 Go to next message
MTMendoza
Messages: 1
Registered: September 2002
Junior Member
Hi!

I have a table (TABLE1) which contains distinct AccountNo and another table(TABLE2) which contains the ff columns: AccountNo(FK to TABLE1),Period(Month and Year) and, AveSales. So each entry to this table corresponds to an account number an a month-year.
I need to get the three highest average sales for each account. How do i do this in PL/SQL?
Thanks!

MTMendoza
Re: Top three records [message #3042 is a reply to message #3041] Sun, 01 September 2002 23:51 Go to previous message
Puneet Vats
Messages: 33
Registered: June 2002
Member
dear,
there is no need to write pl/sql each time You can do it only with a query.

select ac_no from (select ac_no,avg(sale_amount) amt from sales_table group by ac_no order by amt desc)
where rownum < 5;

If u have any other query then plz mail me at vats_puneet@rediffmail.com
Previous Topic: Oracle 11
Next Topic: Database trigger
Goto Forum:
  


Current Time: Thu Apr 18 00:14:44 CDT 2024