From: | "Rodrigo De Leon" <rdeleonp(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: week ending |
Date: | 2006-07-06 07:00:17 |
Message-ID: | a55915760607060000w6b1ce1b8rc5a2eb3aec2ad31e@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 7/5/06, Keith Worthington <KeithW(at)narrowpathinc(dot)com> wrote:
> Hi All,
>
> I just finished writing a query that groups data based on the week number.
>
> SELECT EXTRACT(week FROM col_a) AS week_number,
> sum(col_b) AS col_b_total
> FROM foo
> WHERE foobar
> GROUP BY EXTRACT(week FROM col_a)
> ORDER BY EXTRACT(week FROM col_a);
>
> I would like to generate the starting date or ending date based on this
> number. IOW instead of telling the user "week number" which they won't
> understand I would like to provide either Friday's date for "week
> ending" or Monday's date for "week beginning".
>
> SELECT <something> AS week_ending,
> sum(col_b) AS col_b_total
> FROM foo
> WHERE foobar
> GROUP BY EXTRACT(week FROM col_a)
> ORDER BY EXTRACT(week FROM col_a);
>
> --
>
> Kind Regards,
> Keith
select
max(case when (to_char(col_a,'d') between 2 and 6) then col_a end) as
week_ending,
sum(col_b) as col_b_total from foo
where foobar
group by extract(year from col_a), extract(week from col_a)
order by extract(year from col_a), extract(week from col_a);
Regards,
Rodrigo
From | Date | Subject | |
---|---|---|---|
Next Message | David Clarke | 2006-07-06 10:16:42 | Alternative to serial primary key |
Previous Message | Keith Worthington | 2006-07-06 04:19:54 | week ending |