Using PostgreSQL 9.4.1, I am trying to identify/display the occurrences of values over 3 different columns. See below (apologies for the formatting, I can't get a proper table format. Type, type1 and type2 are the column names.
The table name is 'documents'
Type / Type1 / Type2
USA / China / Africa
China / USA / Chemicals
Chemicals / Africa / USA
Below is \d+ of the table:
Column | Type | Modifiers
----------------+--------+--------------------------------------------------------
id | bigint | not null default nextval('documents_id_seq'::regclass)
title | text |
description | text |
source | text |
url | text |
emaillink | text |
emailurl | text |
type | text |
language | text |
author | text |
publisheddate | date | default ('now'::text)::date
comments | text |
classification | text |
submittedby | text |
localurl | text |
type1 | text |
type2 | text |
Indexes:
"documents_pkey" PRIMARY KEY, btree (id)
I would like a query that returns:
Africa - 2
Chemicals - 2
China - 2
USA - 3
This is a query likely to get run fairly liberally, so I'd like to avoid expensive queries if at all possible.
Any help would be greatly appreciated!
Thanks.