Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用select语句更新动态列值_Mysql_Sql_Sql Server_Database_Stored Procedures - Fatal编程技术网

Mysql 使用select语句更新动态列值

Mysql 使用select语句更新动态列值,mysql,sql,sql-server,database,stored-procedures,Mysql,Sql,Sql Server,Database,Stored Procedures,我有两个临时表:临时1和临时2 临时工1是 Reg Key | Player Name | Age ---------------------------- 1 | Null | Null 2 | Null | Null 3 | Null | Null 临时工2是 Reg Key | Question Name | value ---------------------------- 1 | Player

我有两个临时表:临时1和临时2

临时工1是

Reg Key | Player Name | Age
----------------------------
1       |  Null       | Null
2       |  Null       | Null
3       |  Null       | Null
临时工2是

Reg Key | Question Name | value
----------------------------
1       | Player Name   | Ronaldo
2       | Player Name   | Zedan
1       | Age           | 35
2       | Age           | 38
在temp1中,除了[Reg Key]之外,列名是动态的,例如,我需要在temp1中用[Reg Key]1更新行,在temp2表中用“罗纳尔多”和35更新行


我过去经常循环从temp2和updatetemp1中获取值,但是表temp2中的记录现在超过5000条,所以我尝试创建一个
update
查询,但我不知道如何在运行时获取列名称。

听起来pivot可能会做到这一点:

select 1 as regkey, 'Player Name' as Question_name, 'Ronaldo' as value into #temp2
union all select 2, 'Player Name', 'Zedan'
union all select 1, 'Age', '35'
union all select 2, 'Age', '38'

Select 
    regkey
    , [Player Name]
    , [Age]
From #temp2
Pivot (max(value) for Question_Name in ([Player Name], [Age])) as pvt

tnx给出了pivot表的技巧。我尝试使用pivot表,但它在第一行返回的行数与他们指定的球员姓名Ronaldo相同,在第二行,球员姓名为null,年龄设置为35,而注册号为1。我想在一行中分配这两个值…?请您提供意见