Re: How to write a sql query to get this result?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Daniel <postgresql(at)dunajsky(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to write a sql query to get this result?
Date: 2003-05-01 12:38:02
Message-ID: 20030501123802.GA16742@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Apr 30, 2003 at 21:31:20 -0600,
Daniel <postgresql(at)dunajsky(dot)com> 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(at)hotmail(dot)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(at)postgresql(dot)org)

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-05-01 17:04:20 Re: date use in for loop
Previous Message Ramesh PAtel 2003-05-01 11:30:30 date use in for loop