September 2013
Intermediate to advanced
350 pages
9h 38m
English
The SQL we have seen so far is powerful enough for many everyday tasks, but other questions require more powerful tools. This section introduces a handful and shows when and how they are useful.
Our next task is to calculate the total projected world population for the year 2300. We will do this by adding up the values in PopByRegion’s Population column using the SQL aggregate function SUM:
| | >>> cur.execute('SELECT SUM (Population) FROM PopByRegion') |
| | <sqlite3.Cursor object at 0x102e3e490> |
| | >>> cur.fetchone() |
| | (8965762,) |
SQL provides several other aggregate functions. All of these are associative; that is, the result doesn’t depend on the order of operations. This ensures that the result doesn’t ...
Read now
Unlock full access