Thinking and Summary of Oracle Row and Column Conversion
Thinking and Summary of Oracle Row and Column Conversion the I have been dealing with Oracle-SQL issues in the past few days, and it involves some things that are not usually used, so I have been depressed here for a long time. Now the problem is solved although not perfect. But still share it with everyone. One of row and column conversion: sum (case when.. then.. else.. end) as statement This may also be the first row-to-column conversion method we have encountered. It can be solved by clever use of summary and judgment statements. First look at a simple basic table: as shown below create table STUDENT (www.2cto.com STUNAME NVARCHAR2(50), SUBJECTNAME NVARCHAR2(50), SUBJECTSCORE NUMBER ) the the There are two people’s grades in the table, and each row represents the grades of each student in this subject. This is also a very common table structure when we first learn SQL. Requirement: Convert the above multi-line values into 2-line values in units of students, so that you can intuitively see the grades of each subject of each student. So there is the following statement. select s.stuname, sum(case when s.subjectname='Chinese' then s.subjectscore else 0 end ) as Chinese score, sum(case when s.subjectname='Mathematics'…