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
I admit that must be a more elegant and faster solution with pl/psql (or
whatever other languages)
As I don't know nothing about pl/psql I tried with pure sql (if you don't
have a hunting dog, hunt with a cat)
But obviously this solution doesn't scale well if you have a giant table
with lots
I would be suspicious of this sort of solution of turning rows into
columns by mean of a series of correlated sub-selects. Once the data
set gets large and the number of columns goes over 2 or 3 this will in
all likelihood not perform well.
I had the pleasure of re-writing a "report" which was
Hello, Sandeep,
I am not sure if this is what you want.
I came up with this query
SELECT *
FROM (SELECT user_id,SUM(amount) as day1 FROM t1 WHERE create_timestamp =
'2009-1-1' GROUP BY "user_id") a
NATURAL FULL JOIN (SELECT user_id,SUM(amount) as day2 FROM t1 WHERE
create_timestamp = '2009-1-
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 need to do little modification on the query