Having the sum of two queries

From: Dani Castaños <danitao(dot)mailists(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Having the sum of two queries
Date: 2007-07-16 11:06:21
Message-ID: 469B512D.70507@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleas Mantzios 2007-07-16 11:15:44 Re: Having the sum of two queries
Previous Message chester c young 2007-07-15 16:07:05 Re: data dependent sequences?