Blog Archive for October 8, 2012

Simple Window Function

October 8, 2012

Here's a simple window function, used to work out a count of rows.

bands_band rows have a link to a regions_region row.

These two queries produce the same results. First, a simple count:

SELECT r.name, count(b.region_id)
FROM regions_region r
INNER JOIN …

Cumulative Totals with SQL Window Functions

October 8, 2012

I have built up a database over the years, and each table has a created column with date time in. I wanted to produce a cumulative total of rows based on the date the row was added. I'm using PostgresSQL8.4.12

Too Many Rows

My first attempt at this produced a …