Re: Can I do this using SQL?

From: Roy Hann <specially_at_processed.almost.meat>
Date: Fri, 10 Feb 2006 09:22:37 -0000
Message-ID: <Ksqdnf7S2P14xnHenZ2dnUVZ8qednZ2d_at_pipex.net>


"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 - 10:22:37 CET

Original text of this message