gpt4 book ai didi

mysql - 将表导入 mysql,并使用标题作为行值

转载 作者:行者123 更新时间:2023-11-29 21:28:20 25 4
gpt4 key购买 nike

我什至不知道如何表达这个问题来搜索它。这是我的表格:

enter image description here

我想将其放入 MySQL 中的一个表中,如下所示:

enter image description here

我不知道如何自动完成此任务。我使用的实际表太大,无法像此示例一样手动执行。任何指导或帮助将不胜感激,谢谢!

最佳答案

MySQL 没有用于逆透视的内置函数,因此您必须使用 UNION ALL:

SELECT 'A' AS Country, Date, A As 'Amount'
FROM yourTable
UNION ALL
SELECT 'B' AS Country, Date, B As 'Amount'
FROM yourTable
UNION ALL
SELECT 'C' AS Country, Date, C As 'Amount'
FROM yourTable
UNION ALL
SELECT 'D' AS Country, Date, D As 'Amount'
FROM yourTable
UNION ALL
SELECT 'E' AS Country, Date, E As 'Amount'
FROM yourTable

关于mysql - 将表导入 mysql,并使用标题作为行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35400456/

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