| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Can I do this using SQL?
"Dieter Noeth" <dnoeth_at_gmx.de> wrote in message
news:dshleb$ml8$1_at_online.de...
> SELECT *
> FROM
> (
> SELECT
> branch_name,
> SUM(acct_balance) AS activity_tot,
> COUNT(cust_id) AS cust_tally,
> ROW_NUMBER() OVER (ORDER BY SUM(acct_balance) DESC) AS rn
> FROM BranchActivity
> GROUP BY branch_name
> ) dt
> WHERE rn <= 10;
Appealing but wrong. And I have the bruises to prove it.
You are just arbitrarily choosing 10 rows, not the all rows with values that would place them in the top 10. (Consider the possibility that acct_balance is identical for all branches.)
Roy Received on Fri Feb 10 2006 - 03:22:37 CST
![]() |
![]() |