时间:2021-07-01 10:21:17 帮助过:4人阅读
SELECT a, b, MAX( c ) AS c
FROM (
SELECT 1 a, 2 b, 3 c
UNION ALL SELECT 2 , 3, 2
UNION ALL SELECT 2 , 1, 5
UNION ALL SELECT 5 , 3, 4
UNION ALL SELECT 3 , 5, 3
UNION ALL SELECT 3 , 4, 7
UNION ALL SELECT 4 , 3, 6
)t
WHERE t.a =3
OR t.b =3
GROUP BY (
IF( t.a < t.b, CONCAT( t.a, ',', t.b ) , CONCAT( t.b, ',', t.a ) )
)