From: Achilleas Mantzios <achill@matrix.gatewaynet.com>
To: pgsql-sql@postgresql.org
Subject: Re: Having the sum of two queries
Date: Mon, 16 Jul 2007 14:15:44 +0300
Message-ID: <200707161415.45307.achill@matrix.gatewaynet.com> (raw)
In-Reply-To: <469B512D.70507@gmail.com>
References: <469B512D.70507@gmail.com>
Στις Δευτέρα 16 Ιούλιος 2007 14:06, ο/η Dani Castaños έγραψε:
> Hi all!
>
> I want to do something like this:
>
> SELECT status, COUNT( status ) AS total
> FROM users
> GROUP BY status
>
> UNION
>
> SELECT status, COUNT(status) AS total
> FROM imported_users
> GROUP BY status
>
>
> And have the result of both added.
>
> I've tried something like
>
> SELECT tot.status, COUNT(total)
> FROM( QUERY A UNION QUERY B ) AS tot
> GROUP BY tot.status
>
> But it doesn't works. It doesn't add the total columns with the same
> status...
It should also be UNION ALL, just in case some status'es are common in the 2
subqueries.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
--
Achilleas Mantzios
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: achill@matrix.gatewaynet.com
Subject: Re: Having the sum of two queries
In-Reply-To: <200707161415.45307.achill@matrix.gatewaynet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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