如果有的人某些科目没考,不一定都考这5科, 有的只考2科:
select a.id, a.n, b.km_s, c.km_y, d.km_y, e.km_h, f.km_w from (select id, n from tt group by n) as a left join (select s as km_s,n from tt where k='数学') as b on a.n=b.n left join (select s as km_y,n from tt where k='语文') as c on a.n=c.n left join (select s as km_y,n from tt where k='英语') as d on a.n=d.n left join (select s as km_h,n from tt where k='化学') as e on a.n=e.n left join (select s as km_w,n from tt where k='物理') as f on a.n=f.n order by a.id;tt: 表名n: 名字k: 科目s: 分数
希望能帮到你,别忘了采纳我的答案哦,祝你生活愉快!