pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hélder M. Vieira <hmv@mail.telepac.pt>
To: pgsql-sql@postgresql.org
Subject: Re: Having the sum of two queries
Date: Mon, 16 Jul 2007 23:00:47 +0100
Message-ID: <001401c7c7f4$c4515280$6200a8c0@hmv02> (raw)
References: <469B512D.70507@gmail.com>

>... 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 




view thread (5+ messages)  latest in thread

Message-ID: <001401c7c7f4$c4515280$6200a8c0@hmv02>
Permalink:  ../001401c7c7f4$c4515280$6200a8c0@hmv02/
Also on:    postgresql.org/message-id/001401c7c7f4$c4515280$6200a8c0@hmv02

 · 

reply

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: hmv@mail.telepac.pt
  Subject: Re: Having the sum of two queries
  In-Reply-To: <001401c7c7f4$c4515280$6200a8c0@hmv02>

* 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