gpt4 book ai didi

mysql - 使用 select 语句更新动态列值

转载 作者:行者123 更新时间:2023-11-30 00:07:24 25 4
gpt4 key购买 nike

我有两个临时表:temp1 和 temp 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

在临时 1 中,除 [Reg Key] 之外的列名称是动态的,例如,我需要使用临时表 2 中的“Ronaldo”和 35 更新临时 1 中的 [Reg Key] 1 行。

我曾经循环获取 temp 2 中的值并更新 temp 1,但表 temp 2 中的记录现在超过 5000 条,因此我尝试创建一个 UPDATE 查询,但我不知道如何在运行时获取列名称。

最佳答案

听起来枢轴可能会起作用:

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

关于mysql - 使用 select 语句更新动态列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24409834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com