SQL implementation Vertical table variable horizontal table

Source: Internet
Author: User

All of the online crossbar conversion is a one-size-fits-all, reference value is not, and only suitable for that data volume fixed student score table of the vertical transformation, but when really encountered large data volume conversion is not feasible, the following describes a relatively flexible large amount of data in the horizontal table conversion:

Table structure:

as shown in, where index_id ends with a 0 representation of the service name, ending with 1 for the device RAC name, and 2 at the end of the device state.

below we need to put a set of 0,1,2 end of the separate display as the service name, the device RAC name, the device status of the table header row of data, multiple sets of 0,1,2 end of the display of multiple rows of data.

SQL executes as follows:

Selectindex_id/Ten  asNmmMax( CaseMoD (index_id,Ten) when 0  ThenMon_indexdata.valueElse "' End) Cluster_Name,Max( CaseMoD (index_id,Ten) when 1  ThenMon_indexdata.valueElse "' End) Sys_name,Max( CaseMoD (index_id,Ten) when 2  ThenMon_indexdata.valueElse "' End) State fromMon_indexdatawhereUid= '110100224'  andindex_id>3010000 Group  byindex_id/Ten

The main rule is to group by the 10 and the second-to-last number of inde_id.

SQL implementation Vertical table variable horizontal table

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.