1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| SELECT cnt1.col_1
, cnt2.col_1
FROM ( SELECT t1.col_1
, COUNT(*) AS cnt
FROM matable as t1
GROUP BY t1.col_1
) AS cnt1
INNER JOIN
( SELECT t2.col_1
, COUNT(*) AS cnt
FROM matable AS t2
GROUP BY t2.col_1
) AS cnt2
ON cnt1.cnt = cnt2.cnt
AND cnt1.col_1 > cnt2.col_1
INNER JOIN
( SELECT t3.col_1 AS id1
, t4.col_1 AS id2
, count(*) AS cnt
FROM matable AS t3
INNER JOIN
matable AS t4
ON t3.col_1 > t4.col_1
AND t3.col_2 = t4.col_2
AND t3.col_3 = t4.col_3
AND t3.col_4 = t4.col_4
GROUP BY t3.col_1
, t4.col_1
) AS chps
ON cnt1.cnt = chps.cnt
AND cnt1.col_1 = chps.id1
AND cnt2.col_1 = chps.id2
; |
Partager