SQL Horizontal table conversion and comparison

Source: Internet
Author: User

Horizontal Table to longitudinal table

Horizontal table Style:

SQL statements:

1 SelectName,'language'  asSubjects, Chinese asResults fromHorizontaltab2 Union All3 SelectName,'Mathematics'  asSubjects, Math asResults fromHorizontaltab4 Union All5 SelectName,'English'  asSubjects, 中文版 asResults fromHorizontaltab6Order by Name, account desc

Conversion Result:

Advantages and disadvantages of horizontal table:

Advantage: One line is an entity.

Cons: Add a field and need to re-build the table.

Conclusion: A table with small changes can use a horizontal table.

-----------------------------------------------------------

longitudinal table to Horizontal table

Chart Style:

SQL statements:

1 SelectName,sum ( CaseWhen Course=n'language'Then gradeElse 0End as 'language',2SUM ( CaseWhen Course=n'Mathematics'Then gradeElse 0End as 'Mathematics',3SUM ( CaseWhen Course=n'English'Then gradeElse 0End as 'English'4  fromVerticaltab GROUP BY Name

Conversion Result:

Advantages and disadvantages of the longitudinal table:

Advantages: Easy to add fields.

Cons: The relationship between data is not clear, there will be a surge in data volume situation.

Conclusion: It is possible to consider the longitudinal table for the table with frequent alteration of uncertainties.

SQL Horizontal table conversion and comparison

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.