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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| ||||
| 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 |