SQL vertical table to horizontal table, SQL vertical table

Source: Internet
Author: User

SQL vertical table to horizontal table, SQL vertical table

Converts a vertical table to a horizontal table in the database.

Database vertical table data


The SQL statement is as follows:

Select cardid, max (case t. projectcode when 'ia-002' then t. result end) as ht, max (case t. projectcode when 'ia-003 'then t. result end) as wt, max (case t. projectcode when 'ia-005 'then t. result end) as bmi, max (case t. projectcode when 'ia-000' then t. result end) as xl, max (case t. projectcode when 'cg-005 'then t. result end) as xybhd, max (case t. projectcode when 'CD-002' then t. result end) as kfxt, max (case t. projectcode when 'CD-003 'then t. result end) as chxt, max (case t. projectcode when 'ia-014' then t. result end) as xy, max (case t. projectcode when 'ja-001' then t. result end) as xd, datetime from projectresultinfo t group by t. cardid order by datetime desc


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.