Re: Having the sum of two queries - Mailing list pgsql-sql

From Hélder M. Vieira
Subject Re: Having the sum of two queries
Date
Msg-id 001401c7c7f4$c4515280$6200a8c0@hmv02
Whole thread Raw
In response to Having the sum of two queries  (Dani Castaños <danitao.mailists@gmail.com>)
Responses Re: Having the sum of two queries
List pgsql-sql
>... 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...
>...


I guess you have two problems, if I understand what you're trying to do.
- As Roberto Spier noted, 'sum' would be better than 'count' in the outer 
query.
- Also, 'union' will silently remove duplicate rows, unless you use 'union 
all'.

Please check if this is what you want:

select status, count(status)
from
(
select status from users
union all
select status from imported_users
) as fff
group by status;


Regards,
´
Helder M. Vieira 



pgsql-sql by date:

Previous
From: Dmitry Turin
Date:
Subject: Re: [OBORONA-SPAM] calling webservice through postgresql function
Next
From: "Jyoti Seth"
Date:
Subject: Re: [OBORONA-SPAM] calling webservice through postgresql function