X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id ED2C49FAE4E for ; Thu, 6 Jul 2006 01:20:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 94744-03 for ; Thu, 6 Jul 2006 01:20:43 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id A36639FAD5A for ; Thu, 6 Jul 2006 01:20:43 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mxsf02.cluster1.charter.net (mxsf02.cluster1.charter.net [209.225.28.202]) by svr4.postgresql.org (Postfix) with ESMTP id 14F8A5AF859 for ; Thu, 6 Jul 2006 04:20:02 +0000 (GMT) Received: from mxip10a.cluster1.charter.net (mxip10a.cluster1.charter.net [209.225.28.140]) by mxsf02.cluster1.charter.net (8.12.11/8.12.11) with ESMTP id k664Jxkf005260 for ; Thu, 6 Jul 2006 00:20:00 -0400 Received: from 68-118-182-213.dhcp.nwtn.ct.charter.com (HELO [192.168.116.101]) ([68.118.182.213]) by mxip10a.cluster1.charter.net with ESMTP; 06 Jul 2006 00:19:59 -0400 X-IronPort-AV: i="4.06,211,1149480000"; d="scan'208"; a="549874096:sNHT75833712" Message-ID: <44AC8F6A.4090704@NarrowPathInc.com> Date: Thu, 06 Jul 2006 00:19:54 -0400 From: Keith Worthington Reply-To: KeithW@NarrowPathInc.com Organization: Narrow Path, Inc. User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: week ending Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/51 X-Sequence-Number: 25625 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 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