| From: | Sebastian Böhm <seb(at)exse(dot)net> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | subquery question |
| Date: | 2009-03-13 03:06:45 |
| Message-ID: | 3EF4BFF7-4E37-41C0-BEBF-8DE94DCEF322@exse.net |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Hi,
I have a table: (date timestamp, id integer, value integer)
What Iam trying to do is to get a result that looks like this:
day sum_odd sum_even
2009-01-01 6565 78867
2009-01-02 876785 87667
basically a need to combine these two queries into one:
SELECT date_trunc('day',date) AS day, sum(value) AS sum_odd
FROM xyz WHERE id % 2 = 1 GROUP BY date_trunc('day',date)
SELECT date_trunc('day',date) AS day, sum(value) AS sum_even
FROM xyz WHERE id % 2 = 0 GROUP BY date_trunc('day',date)
I found various ways to do this via unions or joins, but none of them
seem efficient, what is the best way to do that ?
thank you very much
Sebastian
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bob Henkel | 2009-03-13 04:31:06 | Re: subquery question |
| Previous Message | Lennin Caro | 2009-03-12 18:54:30 | Re: Permanent alias for postgresql table |