A question about the data format. thank you for your help.

Source: Internet
Author: User
A data format problem occurs online. thanks for Table 1: & nbsp; idgroupnameattributeopvalue & nbsp; 1 abcDownload: 151-250 & nbsp; 2 abcupload: 50-150 & nbsp; 3efg: a data format issue, online, etc. experts can help you. thank you!
Table 1:
Id groupname attribute op value
1 abc Download: = 151-250
2 abc upload: = 50-150
3 efg Download := 152-250
4 efg upload: = 50-150
How to convert the data in the table to the following format
Id groupname Download upload
1 abc 151-250 50-150
2 efg 152-250 50-150
SQL:
SELECT. groupname,. value AS upload, B. value AS Download FROM radgroupreply a left join radgroupreply B ON. groupname = B. groupname WHERE. attribute = 'upload' AND B. attribute = 'Download' AND. groupname IN ('ABC', 'efg ')
This method can be implemented, but it feels a little inefficient. Is there a better solution?
It is more efficient to use a temporary table than the above method. if a temporary table is used, how can we insert data into the temporary table? if we directly create and execute the preceding SQL statements, this makes no sense, is there any good way to insert it?
This table contains a large amount of data. Considering the efficiency issue, I would like to find a better solution. please help me and give me some ideas. thank you very much!
Online, etc. Urgent !!!!!

------ Solution --------------------
Use the stored procedures to create a temporary table
------ Solution --------------------
This is a cross tabulation, and there are ready-made stored procedures for your reference. Search for "cross tabulation" to find


------ Solution --------------------
Conversion of rows and columns ......
SQL code
Set @ id = ""; select (@ id: = @ id + 1) AS id, groupname, group_concat (if (attribute = 'download', 'value ','') separator '') AS Download, group_concat (if (attribute = 'upload', 'value','') separator '') AS upload from table name group by groupname

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.