Creating column aliases, Aggregating data – Pitney Bowes MapInfo Professional User Manual

Page 251

Advertising
background image

limited to creating one derived column. You can create as many derived columns as you want. Note that
the more derived columns you create, the longer it will take MapInfo Professional to execute the query.

You can also create derived columns based on the aggregate functions count, sum, avg, wtavg, max,
and min. For example:

• sum(Population)

would give you the population for the entire world.

• sum(Area(obj), "sq mi")

would give you the area for the entire world.

Creating Column Aliases

When MapInfo Professional creates a derived column, it uses the expression itself as the name for that
derived column, which can be awkward. You can, however, specify an alias for the column. For example,
the population density column in our DENSITY Browser was titled:

• Population / Area(obj, "sq mi")

To rename the column, add the new name to the Select Columns box when listing the columns.

The alias must follow the expression. It must also be separated from the expression by a blank space
and enclosed in quotes. For example:

• Country, Population / Area(obj, "sq mi") "POP_DENSITY"

When MapInfo Professional creates the temporary query table, the population density column will now
be named POP_DENSITY.

You can use aliases to rename any column in a table, not just derived columns. For example, if each
country in your table is a separate sales territory for your corporation, you might want to rename the
Country column "TERRITORY". The procedure is identical:

• Country "TERRITORY", Population / Area(obj, "sq mi") "POP_DENSITY"

For another example, see Example - Computing Total World Population Density in the Help System.

Aggregating Data

When you aggregate data, you perform a mathematical operation on all of a column's values in all of
the records in your table. Unlike the Select command, which only allows you to perform mathematical
functions on individual records, SQL allows you to aggregate (or summarize) data across records.

MapInfo Professional looks for each unique set of data values in the specified column or columns and
creates one row for each such unique set. When you aggregate data, you need to specify:

• How the records will be grouped.

• How the data will be aggregated (summarized).

For example, you have a table of sales representatives and their sales figures for the past three months:

SALES

MONTH

SALES_REP

1200

May

John

900

May

Cathy

1100

May

Julie

900

June

John

251

MapInfo Professional User Guide

Chapter 9: Selecting and Querying Data

Advertising