pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to write a sql query to get this result?
3+ messages / 3 participants
[nested] [flat]
* How to write a sql query to get this result?
@ 2003-05-01 03:31 Daniel <postgresql@dunajsky.com>
0 siblings, 2 replies; 3+ messages in thread
From: Daniel @ 2003-05-01 03:31 UTC (permalink / raw)
To: pgsql-sql
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.
Please reply to daniel_katka@hotmail.com
Thank you very much.
Daniel
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to write a sql query to get this result?
@ 2003-05-01 06:40 Tomasz Myrta <jasiek@klaster.net>
parent: Daniel <postgresql@dunajsky.com>
1 sibling, 0 replies; 3+ messages in thread
From: Tomasz Myrta @ 2003-05-01 06:40 UTC (permalink / raw)
To: daniel_katka@hotmail.com; +Cc: pgsql-sql
Dnia 2003-05-01 05:31, Uz.ytkownik Daniel napisa?:
> 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.
>
> Please reply to daniel_katka@hotmail.com
Find samething about contrib/tablefunc
This problem is well known as cross tab (pivot table).
Regards,
Tomasz Myrta
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: How to write a sql query to get this result?
@ 2003-05-01 12:38 Bruno Wolff III <bruno@wolff.to>
parent: Daniel <postgresql@dunajsky.com>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2003-05-01 12:38 UTC (permalink / raw)
To: Daniel <postgresql@dunajsky.com>; +Cc: pgsql-sql
On Wed, Apr 30, 2003 at 21:31:20 -0600,
Daniel <postgresql@dunajsky.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@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)
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-05-01 12:38 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-05-01 03:31 How to write a sql query to get this result? Daniel <postgresql@dunajsky.com>
2003-05-01 06:40 ` Tomasz Myrta <jasiek@klaster.net>
2003-05-01 12:38 ` Bruno Wolff III <bruno@wolff.to>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox