--CREATE TABLE STU
--(
-- NAME VARCHAR (50),
-- OBJ VARCHAR (50),
-- RESULT INT
--)
--INSERT INTO STU VALUES('张三','语文',60)
--INSERT INTO STU VALUES('张三','数学',70)
--INSERT INTO STU VALUES('张三','英语',50)
--INSERT INTO STU VALUES('李四','英语',50)
--INSERT INTO STU VALUES('李四','数学',20)
--INSERT INTO STU VALUES('李四','语文',100)
select name,(case OBJ when '语文' then result else 0 end) as 语文,
(case OBJ when '数学' then result else 0 end) as 数学,
(case OBJ when '英语' then result else 0 end) as 英语
from stu 我想要的格式是name 语文 数学 英语
张三 60 70 50请问要如何修改?
max(case OBJ when '数学' then result else 0 end) as 数学,
max(case OBJ when '英语' then result else 0 end) as 英语
from stu
max(case OBJ when '数学' then result else 0 end) as 数学,
max(case OBJ when '英语' then result else 0 end) as 英语
from stu
group by name