Skip site navigation (1) Skip section navigation (2)

Re: Counting booleans for two columns

From: "Oliveiros C," <oliveiros(dot)cristina(at)marktest(dot)pt>
To: "Rikard Bosnjakovic" <rikard(dot)bosnjakovic(at)gmail(dot)com>,<pgsql-novice(at)postgresql(dot)org>
Subject: Re: Counting booleans for two columns
Date: 2009-11-20 14:32:14
Message-ID: FAFAF825E2574E2CB5C2F5EA02A08660@marktestcr.marktest.pt (view raw or flat)
Thread:
Lists: pgsql-novice
Howdy, Rikard,

Try Something like this

SELECT (/* Your first query */) , (/* Your second query*/) ;


Best,
Oliveiros

----- Original Message ----- 
From: "Rikard Bosnjakovic" <rikard(dot)bosnjakovic(at)gmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Sent: Friday, November 20, 2009 2:17 PM
Subject: [NOVICE] Counting booleans for two columns


>I have a table with values similiar to this (I have reduced the number
> of rows from the actual table):
>
> played | stats_exists
> --------+--------------
> t      | t
> t      | f
> t      | t
> t      | t
> f      | t
> t      | t
> t      | f
>
> What I want to do is to count the number of "t" in each column and
> return the values (in two separate columns). The only thing I've
> managed to do is doing a UNION, but this gives me the (correct)
> results in one column only, I want the results in two (I need to
> distinguish between the numbers). I did like this:
>
> SELECT count(played) AS played
> FROM matches
> WHERE origin=1 AND played AND NOT training AND match_date > '2009-08-01'
> UNION
> SELECT count(stats_exists) AS stats
> FROM matches
> WHERE origin=1 AND stats_exists AND NOT training AND match_date > 
> '2009-08-01';
>
> with this result:
>
> played
> --------
>     12         <-- stats
>     13         <-- played
> (2 rows)
>
> How can I rewrite the SELECT so I get two values in separate columns
> instead of two rows?
>
>
> -- 
> - Rikard
>
> -- 
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice 


In response to

pgsql-novice by date

Next:From: Oliveiros C,Date: 2009-11-20 15:06:33
Subject: Re: Counting booleans for two columns
Previous:From: Thom BrownDate: 2009-11-20 14:30:52
Subject: Re: Counting booleans for two columns

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group