[Q] how to convert rows and columns [A] 1. Column and column conversion with fixed columns For example Student subject grade --------------------------- Student1 language 80 Student1 mathematics 70 Student1 English 60 Student2 language 90 Student2 mathematics 80 Student2 100 English ...... Convert Chinese, mathematics, and English Student1 80 70 60 Student2 90 80 100 ...... The statement is as follows: Select student, sum (decode (subject, 'China', grade, null) "", Sum (decode (subject, 'mat', grade, null) "Mathematics ", Sum (decode (subject, 'English ', grade, null) "English" From table group by student 2. Changing columns and columns For example C1 C2 -------------- 1. Me 1 is 1 WHO 2 Zhi 2 channels 3 No ...... Convert 1. Who am I? 2. Know 3 No This type of conversion must be completed by PL/SQL. Here is an example. Create or replace function get_c2 (tmp_c1 number) Return varchar2 Is Col_c2 varchar2 (4000 ); Begin For cur in (select C2 from t where c1 = tmp_c1) loop Col_c2: = col_c2 | cur. C2; End loop; Col_c2: = rtrim (col_c2, 1 ); Return col_c2; End; /SQL> select distinct C1, get_c2 (C1) CC2 from table; |