Crosstab Confusion

From: Adam Sherman <adam(at)sherman(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Crosstab Confusion
Date: 2010-02-01 15:03:40
Message-ID: C5C50165-6162-460C-8E13-A0A76D0B726B@sherman.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I'm really trying to understand how the tablefunc crosstab function works, to no avail.

I have a table that looks like this:

customer_id integer
date timestamp with time zone
amount numeric(10,4)

There are rows in this table every-time a customer gets charged an amount, which is multiple times per day.

I would like to get a result like this:

customer_id,day1,day2,day3,(…)
1,400.00,500.01,123.00,(…)

So, one row for each customer id and a column for every day in the current month. Anyone used crosstab for something like this?

Thanks for your help,

A.

--
www.sherman.ca / +1-613-797-6819 / +1-646-233-3400

"When the burning husks of your startups warm the last of your bones, remember I told you so." - Zed

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Lee Hachadoorian 2010-02-01 16:34:44 Re: Crosstab Confusion
Previous Message Yeb Havinga 2010-02-01 14:52:36 Re: selecting rows tagged with "a" but not "b"