Unix Technical Forum

Help with SQL statement

This is a discussion on Help with SQL statement within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Can anyone help me with the following ? I have a table players, with columns: - player_name - player_village ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 10:29 AM
Bert
 
Posts: n/a
Default Help with SQL statement

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 10:29 AM
Brian Peasland
 
Posts: n/a
Default Re: Help with SQL statement

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@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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 10:29 AM
Bert
 
Posts: n/a
Default Re: Help with SQL statement

Thank you so far.
This querie shows total population for all players with coordinates
within x10-x20 and y10-y20.
But some players also have a village within x10-x20 / y10-y20 AND a
village outside these coordinates.

So I want a query for the TOTAL population for all players with AT
LEAST one village within x10-x20/y10-y20.

Regards,

Bert

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:41 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com