Group by with insensitive order

From: Aram Fingal <fingal(at)multifactorial(dot)com>
To: Postgres-General General <pgsql-general(at)postgresql(dot)org>
Subject: Group by with insensitive order
Date: 2011-01-19 20:37:58
Message-ID: 6DC89F55-57BA-489C-ADF9-9AF09BE1CE28@multifactorial.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Suppose I'm doing a group by query like the following:

SELECT drug1, drug2, AVG(response)
FROM data
GROUP BY drug1, drug2

The problem is that the same drug may appear sometimes as drug1 and sometimes as drug2. So, for example, the combination "aspirin, acetaminophen" may also appear as "acetaminophen, aspirin" and I want these grouped together in the query. Is there a simple way to do this?

--Aram Fingal

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-01-19 20:38:18 Re: Error during a dump (ts_selectivity, not found)
Previous Message Vick Khera 2011-01-19 20:31:23 Re: Error during a dump (ts_selectivity, not found)