OK. I have database which is made from data used in TRAVIAN game. I have 200000 rows, so I want to reduce it for Excel analysis.
x y village player alliance population date
27 -41 h1 h S 35 2009-12-23
27 -41 h1 h S 56 2009-12-24
27 -41 h1 h S 60 2009-12-25
27 -41 h1 h S 89 2009-12-26
These are just some of the important atributes in table. There is a lot of other entries for each village every time when player is logged into system. So you can see the population growing per each village. I just want to write an sql statement which returns me only entry where maximum population of the village is. (for each village of course).
I wrote something like this
SELECT *
FROM x_world
GROUP BY village
HAVING population = max(population)
In theory i want to loop over each village and search for its biggest population entry and take just that one. I want to do this for each village. This is how i will also a total number of villages.
Try this query using joins. It is much faster then dependant subqueries.
Demo