The oracledecode function implements row-to-column conversion.

Source: Internet
Author: User
Use the decode function or casewhen to implement row-to-column Oracle ---- create test table createtablestudent_score (namevarchar2 (20), subjectvarchar2 (20), scorenumber (); ----- insert test data into (name, subject, score) values (Zhang San, Chinese, 78); in

Use the decode function or case when to convert rows to Oracle ---- create a test table create table student_score (name varchar2 (20), subject varchar2 (20), score number )); ----- insert test data insert into student_score (name, subject, score) values ('zhang san', 'China', 78); in

Use the decode function or case when to implement row-to-column Conversion
Oracle
---- Create test table create table student_score (name varchar2 (20), subject varchar2 (20), score number (); ----- insert test data insert into student_score (name, subject, score) values ('zhang san', 'China', 78); insert into student_score (name, subject, score) values ('zhang san', 'mat', 88 ); insert into student_score (name, subject, score) values ('zhang san', 'English ', 98); insert into student_score (name, subject, score) values ('Li si ', 'China', 89); insert into student_score (name, subject, score) values ('lily', 'mat', 76); insert into student_score (name, subject, score) values ('Li si', 'English ', 90); insert into student_score (name, subject, score) values ('wang 5', 'China', 99 ); insert into student_score (name, subject, score) values ('wang wu', 'mate', 66); insert into student_score (name, subject, score) values ('wang wu ', 'English ', 91); ----- select name "name" in the decode line, sum (decode (subject, 'China', nvl (score, 0), 0 )) "language", sum (decode (subject, 'mat', nvl (score, 0), 0) "Mathematics", sum (decode (subject, 'English ', nvl (score, 0), 0) "English" from student_score group by name; ------ select name "name ", sum (case when subject = 'China' then nvl (score, 0) else 0 end) "", sum (case when subject = 'mate' then nvl (score, 0) else 0 end) "Mathematics", sum (case when subject = 'English 'then nvl (score, 0) else 0 end) "English" from student_score group by name;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.