Grouping
Use SQL to write queries that group results. Grouping is a powerful facility for summarizing data, particularly in combination with aggregates such as COUNT or SUM.
SELECT COUNT(name), population FROM cities GROUP BY population;
This query returns the number of cities that have the same population for each distinct population value that appears in the table. The GROUP BY clause breaks the set of result rows into groups with equal populations; then the target list is evaluated for each group separately. The COUNT aggregate counts the number of city names in the group.
Consider whether any of the types you define are candidates for grouping. In the SimpleMap DataBlade® module, for example, polygons are a poor candidate; users seldom want to group geographic data that contains identical polygons.
SELECT Area(boundary) / 10 AS dimensions, SUM(population)
FROM cities GROUP BY dimensions;
- For each type in the DataBlade module, can the values sensibly be broken into groups that are equivalent?
- What is the meaning of each of these groups?
- Do users want to group values in that way?