gpt4 book ai didi

sql - 取查询数据建新表

转载 作者:行者123 更新时间:2023-12-01 12:50:47 25 4
gpt4 key购买 nike

我有一个表,我对其运行查询并获得如下结果:

-----------------------------------------------------------------------------------------------
Account January February March April May June July August September October November December
-----------------------------------------------------------------------------------------------
1234 0 50 100 0 0 0 120 280 800 0 650 124
-----------------------------------------------------------------------------------------------

如何转换此查询以显示如下数据:

------------------------
Account Period Amount
-------------------------
1234 Jan 0
1234 Feb 50
1234 Mar 100
.
.
1234 Dec 124
--------------------------

我会创建 View 、存储过程或其他东西吗? (请原谅我缺乏知识,因为我不是真正的 DBA,但需要找到解决方案来协助解决这个问题。)

最佳答案

你可以用类似这样的查询来显示它:

SELECT Account, 'Jan' as Period, January as Amount
FROM myTable

UNION ALL

SELECT Account, 'Feb' as Period, February as Amount
FROM myTable

UNION ALL

...

关于sql - 取查询数据建新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9638986/

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