I am trying to check if there are better solution to this query question:
Find the pairs of PC models having identical speeds and RAM.
As a result, each resulting pair is shown only once, i.e. (i, j) but not (j, i). Result set: model with higher number, model with lower number, speed, and RAM.
I came up with:
select max(model), min(model), speed, ram
from PC
group by speed, ram
having count(model) = 2 and max(model) <> min(model)
and get
speed ram
--------------------------------
1260 1232 500 32
1233 1232 500 64
1233 1121 750 128
The PC table looks like this:
model speed ram
------------------------
1232 500 64
1121 750 128
1233 500 64
1121 600 128
1121 600 128
1233 750 128
1232 500 32
1232 450 64
1232 450 32
1260 500 32
1233 900 128
1233 800 128