CREATE TABLE tb(name VARCHAR(10) , course VARCHAR(10) , score INT)
INSERT INTO tb(name,course,score) VALUES
('张三' , '语文' , 74),
('张三' , '数学' , 83),
('张三' , '物理' , 93),
('李四' , '语文' , 74),
('李四' , '数学' , 84),
('李四' , '物理' , 94),
('王五' , '语文' , 88),
('王五' , '数学' , 89),
('王五' , '物理' , 98),
('赵六' , '语文' , 80),
('赵六' , '数学' , 82),
('赵六' , '物理' , 88);
SELECT name AS 姓名,
MAX(CASE course WHEN '语文' THEN score ELSE 0 END) 语文,
MAX(CASE course WHEN '数学' THEN score ELSE 0 END) 数学,
MAX(CASE course WHEN '物理' THEN SCORE ELSE 0 END) 物理
FROM TB
GROUP BY name