A typical approach to SQL Server and Oracle Row-column

Source: Internet
Author: User

For some businesses, the data stored in the table and its final grid performance is exactly the equivalent of reversing the source table, so this time we have a problem of how to convert rows into columns, and to simplify the problem, we look at the following query data, you do not have to care about the design of the table and SQL statements:

Suppose the SQL statement used is:

SELECT [姓名],[时代],[金钱]
FROM [test].[dbo].[people]

This table stores the gold coins owned by two people in different eras (times are fixed by three: young, middle-aged and old), of which:

John has 1000, 5000 and 800 gold coins in young, middle-aged and old age respectively;

Dick has 1200, 6000, and 500 gold coins in young, middle-aged and old age respectively.

Now we want to show the coins that two people have at different stages in a form similar to the following:

Name Young Middle Elderly
Tom 1000 5000 800
John doe 1200 6000 500

Related Article

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.