Simple SQL statement for Oracle row-to-column Conversion

Source: Internet
Author: User

Drop table ABC;

Create table ABC (id number, name varchar2 (50), kcName varchar2 (50), score number );
Insert into ABC values (1, 'zhang san', 'China', 88 );
Insert into ABC values (2, 'zhang san', 'mat', 68 );
Insert into ABC values (3, 'zhang san', 'English ', 78 );

Insert into ABC values (4, 'Li si', 'English ', 78 );
Insert into ABC values (5, 'Li si', 'China', 88 );
Insert into ABC values (6, 'lily', 'mat', 79 );

Insert into ABC values (7, 'wang wu', 'English ', 74 );
Insert into ABC values (8, 'wang wu', 'China', 58 );
Insert into ABC values (9, 'wang wu', 'mat', 98 );

Select * from abc;
Select abc. Name, sum (decode (kcName, 'China', SCORE, null) language,
Sum (decode (kcName, 'mat', SCORE, null) mathematics,
Sum (decode (kcName, 'English ', SCORE, null) English
From abc group by abc. name;

Result:
NAME Chinese Mathematical English
1 Wang Wu 158 198 174
2 Li Si 188 179 178
3 Zhang San 188 168 178

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.