Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
On Mon, Feb 1, 2010 at 3:11 PM, Adam Sherman wrote: > Actually, the query I was running is: > > SELECT >cust_id as customer, >date_trunc(''day'', date) AS day, > SUM(billed_duration)/60.0::numeric(10,4) AS minutes > > billed_duration is an integer. Make sense? > > If billed_duration i

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
On 2010-02-01, at 14:22 , Lee Hachadoorian wrote: > The output column data type (day1, day2, etc.) is supposed to match the value > data type. I used numeric(10,4) because that's what your original post > specified, but the billed_duration column in your most recent post looks like > it might be

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
The output column data type (day1, day2, etc.) is supposed to match the value data type. I used numeric(10,4) because that's what your original post specified, but the billed_duration column in your most recent post looks like it might be integer? (Or is it defined as numeric(10,4), but you never e

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
On 2010-02-01, at 11:34 , Lee Hachadoorian wrote: > You basically have three parts: > > 1) SELECT query in the form (row header, column header, cell value). In this > case it is an aggregate query so that you can sum the transactions over a > given day. > > 2) List of column headers. If you wa

Re: [SQL] Crosstab Confusion

2010-02-01 Thread Lee Hachadoorian
I'm flying blind here since I have nothing that looks like the structure you described to experiment on, but based on some crosstabs I have set up this should get you started. Explanatory notes follow. SELECT pivot.* FROM crosstab(' --row header, column header, cell value SELECT customer_i

[SQL] Crosstab Confusion

2010-02-01 Thread Adam Sherman
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