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