日期:2014-05-17 浏览次数:20367 次
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 ) )
)