WITH scores AS ( SELECT '小' AS A, 28 AS 列, 69 AS 列2, 67 AS 列3 UNION ALL SELECT '王' AS A, 26 AS 列, 78 AS 列2, 9 AS 列3 UNION ALL SELECT '朱' AS A, 34 AS 列, 100 AS 列2, 11 AS 列3 UNION ALL SELECT '李' AS A, 99 AS 列, 2 AS 列2, 100 AS 列3 ) SELECT A, MAX(列) AS 列 , MAX(列2) AS 列2 , MAX(列3) AS 列3 FROM ( SELECT A, 列 , 0 AS 列2 , 0 AS 列3 FROM scores WHERE 列 = ( SELECT MAX(列) FROM scores ) UNION SELECT A, 0 AS 列, 列2 , 0 AS 列3 FROM scores WHERE 列2 = ( SELECT MAX(列2 ) FROM scores ) UNION SELECT A, 0 AS 列, 0 AS 列2 , 列3 FROM scores WHERE 列3 = ( SELECT MAX(列3 ) FROM scores ) ) T5 GROUP BY A
|