is a 'pairwise' possible / feasible in SQL? - Mailing list pgsql-general

From Rajarshi Guha
Subject is a 'pairwise' possible / feasible in SQL?
Date
Msg-id 032F8CAC-875F-4ECC-88CF-C0E3531C0D3E@indiana.edu
Whole thread Raw
Responses Re: is a 'pairwise' possible / feasible in SQL?
Re: is a 'pairwise' possible / feasible in SQL?
List pgsql-general
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, I have a table of the form

aid     cid
- ----   -----
1      123
2      456
3      667
3      879
3      123
4      878
4      456
4      123
5      999
5      667
5      879

My goal is to identify for each pair of cid values, the number of
times they have the same aid

Thus for example I would have

pair        count
- ----        -----
123 & 456   1
667 & 879   2
...

I currently do this by using a Python script to do a pairwise lookup, as

select count(aid) where cid = 123 and cid = 456;

but I was wondering whether I could construct a single SQL statement
to do this.

Any pointers would be appreciated,

Thanks,
- -------------------------------------------------------------------
Rajarshi Guha  <rguha@indiana.edu>
GPG Fingerprint: D070 5427 CC5B 7938 929C  DD13 66A1 922C 51E7 9E84
- -------------------------------------------------------------------
All great discoveries are made by mistake.
    -- Young


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkiXRYUACgkQZqGSLFHnnoTJJQCgtvromGcYfQVGsekGFQJU6vTo
oHgAnjpfKSkZR0MqBjdE6WFGO8SBr2WH
=zZJk
-----END PGP SIGNATURE-----

pgsql-general by date:

Previous
From: Greg Smith
Date:
Subject: Re: recovery via base + WAL replay failure
Next
From: Lennin Caro
Date:
Subject: Re: recovery via base + WAL replay failure