X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 666C25285A for ; Wed, 3 Aug 2005 12:30:00 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 93295-01 for ; Wed, 3 Aug 2005 15:29:52 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 5E6D45285B for ; Wed, 3 Aug 2005 12:29:50 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 6A1103095A; Wed, 3 Aug 2005 17:38:28 +0200 (MET DST) From: "codeWarrior" X-Newsgroups: pgsql.sql Subject: Re: Breakdown results by month Date: Wed, 3 Aug 2005 08:38:18 -0700 Organization: Hub.Org Networking Services Lines: 50 Message-ID: References: <2bffcc3305080211342745b1ab@mail.gmail.com> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Original To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.234 tagged_above=0 required=5 tests=AWL, FORGED_HOTMAIL_RCVD2, PRIORITY_NO_NAME X-Spam-Level: ** X-Archive-Number: 200508/16 X-Sequence-Number: 22244 You are looking for what is commonly referred to as a "pivot-table" or a "cross-tab". Pivot-tables are a fairly sophisticated, non-normalized view of a dataset, nd most commonly appear in spreadsheets and are used for financial or statistical analysis. These queries typically use an aggregate function (sum, min, max, etc....) and a "group by" clause when generated from an SQL query... There are lots of decent tutorials / samples out there (Google for "Pivot Table SQL" and you'll see...) http://www.windowsitpro.com/Files/09/15608/Listing_01.txt http://mail.python.org/pipermail/python-list/2005-February/264233.html "Henry Ortega" wrote in message news:2bffcc3305080211342745b1ab@mail.gmail.com... >I have the ff table: > > id | total | effective | end_date > john 6 01-01-2005 02-28-2005 > john 8 03-01-2005 06-30-2005 > > How can I return: > id | total | effective | end_date > john 6 01-01-2005 01-31-2005 > john 6 02-01-2005 02-28-2005 > john 8 03-01-2005 03-31-2005 > john 8 04-01-2005 04-30-2005 > john 8 05-01-2005 05-31-2005 > john 8 06-01-2005 06-30-2005 > > Any help would be appreciated. Thanks > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq >