Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Help with SQL statement

Re: Help with SQL statement

From: Brian Peasland <oracle_dba_at_nospam.peasland.net>
Date: Wed, 17 May 2006 14:33:50 GMT
Message-ID: <IzEz4G.KFx@igsrsparc2.er.usgs.gov>


Bert wrote:
> Can anyone help me with the following ?
>
> I have a table players, with columns:
> - player_name
> - player_village
> - village_population
> - X-coordinate
> - Y-coordinate
>
> A player can have 1 or more villages (it's for a computer game). Each
> village has a population.
>
> For all players within coordinates X10-X20 and Y10-Y20 I want their
> total population of ALL their villages.
>
> Can anyone help me ?
>
> Bert
>

SELECT player_name,SUM(village_population) FROM table
WHERE x-coordinate BETWEEN x10 and x20

   AND y-coordinate BETWEEN y10 and y20
GROUP BY player_name;

You will be summing the population for each player. The SUM function is an aggregate function which means you'll need to tell Oracle how to aggregate "like" or similar data. That is precisely what the GROUP BY clause does.

HTH,
Brian

-- 
===================================================================

Brian Peasland
oracle_dba_at_nospam.peasland.net
http://www.peasland.net

Remove the "nospam." from the email address to email me.


"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown
Received on Wed May 17 2006 - 09:33:50 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US