oracle行转列


select i.sid,i.sname,i.birthday,i.schooltime,i.sphone,c.classname,a.assnname,sum(decode(subject,'语文',s.score,0)) as chin, 
                                    sum(decode(subject,'数学',s.score,0)) as math, 
                                    sum(decode(subject,'英语',s.score,0)) as eng from student_info i 
left join student_expand e on i.sid = e.sid left join student_class c on
        c.classid = e.classid left join student_assn a on a.assnid = e.assnid left join student_score s on s.sid = i.sid 
group by i.sid,i.sname,i.birthday,i.schooltime,i.sphone,c.classname,a.assnname;

行转列:
decode(subject,'数学',s.score,0) 用法:如果subject会等于数学 ,则最后值等于 s.score 否则值等于: 0


 

你可能感兴趣的:(oracle,sql,C++,c,C#)