Assuming you know your dates beforehand, you could try a CASE
statement. Something like:
select
order_id,
sum(case when timestamp::date = 01/01/2009'' then amount else 0 end)
as amount_day1,
sum(case when timestamp::date = '02/01/2009' then amount else 0 end)
as amount_day2,
sum(case when t
2009/6/25 James Kitambara :
>
> Hello Mr. Sandeep Bandela,
>
> I have gone through your scenario and come up with the following solution.
>
> SELECT USER_ID, CREATE_TIMESTAMP::DATE, SUM(AMOUNT)
> FROM ORDERS
> GROUP BY USER_ID, CREATE_TIMESTAMP
> ORDER BY USER_ID, CREATE_TIMESTAMP;
>
> Maybe you ne
ant table
with lots of columns
- Original Message -
From: "Rob Sargent"
To:
Sent: Thursday, June 25, 2009 4:57 PM
Subject: Re: [SQL] Bucketing Row Data in columns
I would be suspicious of this sort of solution of turning rows into columns
by mean of a series of correlated su
mailto:gibsos...@gmail.com>
*To:* pgsql-sql@postgresql.org <mailto:pgsql-sql@postgresql.org>
*Sent:* Wednesday, June 24, 2009 5:39 PM
*Subject:* [SQL] Bucketing Row Data in columns
Hi all,
I need help on creating a sql, not a problem even if its pl/sql
I have orders table sche
e -
From: Sandeep
To: pgsql-sql@postgresql.org
Sent: Wednesday, June 24, 2009 5:39 PM
Subject: [SQL] Bucketing Row Data in columns
Hi all,
I need help on creating a sql, not a problem even if its pl/sql
I have orders table schema is as follow
orders(order_id,user_id, create
to get what you want.
Best Regards
James Kitambara
Database Administrator
-ORGINAL
MESSAGE
--- On Wed, 24/6/09, Sandeep wrote:
From: Sandeep
Subject: [SQL] Bucketing Row Data in columns
To: pgsql-sql
Hi all,
I need help on creating a sql, not a problem even if its pl/sql
I have orders table schema is as follow
orders(order_id,user_id, create_timestamp, amount)
and I want to generate a report like
for the past 3 days bucketing purchases i.e SUM(amount) every day in
columns
i.e result will be