Re: Having the sum of two queries

Поиск
Список
Период
Сортировка
От Achilleas Mantzios
Тема Re: Having the sum of two queries
Дата
Msg-id 200707161415.45307.achill@matrix.gatewaynet.com
обсуждение исходный текст
Ответ на Having the sum of two queries  (Dani Castaños <danitao.mailists@gmail.com>)
Список pgsql-sql
Στις Δευτέρα 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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Dani Castaños
Дата:
Сообщение: Having the sum of two queries
Следующее
От: Roberto Spier
Дата:
Сообщение: Re: Having the sum of two queries