Home > database >  A MySQL line column dynamic storage process
A MySQL line column dynamic storage process

Time:10-28

Below is I write one line according to the result of an SQL query dynamic column of SQL statements, now I have a question, how to dynamically from the result will be specified in the column of data transfer in data, "CallType" is now a static field, can run successfully, but I need to convert CallType to columnname
 
The BEGIN

Drop table if the exists temptable1;

The Set @ sq1=CONCAT (' the Create table temptable1 () ', SQLSTR, ' ');
PREPARE stmt1 FROM @ sq1;
The EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;

The SET @ EE=' ';

SELECT
GROUP_CONCAT (DISTINCT
CONCAT (
'the SUM (IF (b.', columnname, '=' ' ', CallType, ' ' ', b. ', rowname, ', 0)) AS ' ' ', CallType, ' ' ' ')
) into @ EE
The FROM temptable1 c;

Select @ EE;
- SELECT
- GROUP_CONCAT (DISTINCT
- CONCAT (
- 'the SUM (the IF (b.' ' ', columnname, ' ' '=' ' ',
- Arthur c. allType,
- "' biggest c, 0)) AS the ' ' ',
- Arthur c. allType, '"'
-)
-) into @ EE
- the FROM reportcall c;




The SET @ QQ=CONCAT (' select '@ EE,' the from temptable1 b ', sort);
SELECT @ QQ;
PREPARE STMT FROM @ QQ;
The EXECUTE STMT.
DEALLOCATE PREPARE STMT.
END

CodePudding user response:

There is no table structure, tell me about what you want,
  • Related