X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A7DFA475F6A for ; Thu, 1 May 2003 08:37:03 -0400 (EDT) Received: from wolff.to (wolff.to [66.93.249.74]) by postgresql.org (Postfix) with SMTP id E7284475F16 for ; Thu, 1 May 2003 08:37:02 -0400 (EDT) Received: (qmail 16850 invoked by uid 500); 1 May 2003 12:38:02 -0000 Date: Thu, 1 May 2003 07:38:02 -0500 From: Bruno Wolff III To: Daniel Cc: pgsql-sql@postgresql.org Subject: Re: How to write a sql query to get this result? Message-ID: <20030501123802.GA16742@wolff.to> Mail-Followup-To: Daniel , pgsql-sql@postgresql.org References: <020601c30f92$22174ca0$0300a8c0@akssk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <020601c30f92$22174ca0$0300a8c0@akssk> User-Agent: Mutt/1.5.4i X-Spam-Status: No, hits=-38.6 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, QUOTE_TWICE_1,REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_MUTT autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/6 X-Sequence-Number: 13171 On Wed, Apr 30, 2003 at 21:31:20 -0600, Daniel wrote: > Hello, > > Is there any way how to retrieve result normally displayed as: > > TOTAL 268 > Administrator 7 > Internet Only 178 > Filtered Internet 7 > > To be like this: > > TOTAL Administrator Internet Only Filtered Internet > 268 7 178 7 > > That means, the rows of the first column of the first case are headers in > the second case. Similarly, the rows of the second column are displayed as > one row. For a fixed set of rows, you can combine the queries together into one query. If the number of rows is data dependent, then you will want to look at the crosstab contribution as suggested in another response. You can do something like: select (select total_query) as "TOTAL", (select administrator_query) as "Administrator", (select internet_query) as "Internet Only", (select filtered_query) as "Filtered Internet"; > > Please reply to daniel_katka@hotmail.com Please use a reply-to header to redirect replies. (Or change your from address.) > > Thank you very much. > > Daniel > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)