gpt4 book ai didi

SQL:使用查询结果创建新表

转载 作者:行者123 更新时间:2023-12-04 13:44:34 24 4
gpt4 key购买 nike

我在查询中计算了一些新列,我想知道是否可以将查询结果保存到新表/工作表中。因此,当我打开新表时,我可以看到查询结果,而无需每次打开 SQL 时都重新运行查询。

这是我正在使用的代码:

SELECT a.[CUSIP NUMBER],
a.[CURRENT BALANCE],
a.[ORIGINAL WA MATURITY],
a.[CURRENT WA MATURITY],
a.[PASS THRU RATE] [PASS THRU RATE],
a.[CURRENT FACTOR],
b.[CURRENT FACTOR],
b.[ORIGINAL BALANCE],
MonthlyRate,
Payment,
InterestPayment,
Principle,
ScheduledFace,
PreviousFace,
ScheduledFactor,
SMM,
CPR
FROM DBO.mbs032013 a
JOIN dbo.mbs042013 b ON a.[CUSIP NUMBER] = b.[CUSIP NUMBER]
CROSS APPLY (Select (a.[PASS THRU RATE]*.01)/12) CA(MonthlyRate)
CROSS APPLY (Select (a.[CURRENT BALANCE] * ((MonthlyRate)/((1-(1/power(1+ MonthlyRate, a.[CURRENT WA MATURITY]))))))) CA2(Payment)
Cross Apply (Select a.[CURRENT BALANCE] * MonthlyRate) CA3 (InterestPayment)
Cross Apply (Select Payment - InterestPayment) CA4 (Principle)
Cross Apply (Select a.[ORIGINAL BALANCE] * a.[CURRENT FACTOR]) CA5 (PreviousFace)
CROSS APPLY (Select PreviousFace - Principle) CA6(ScheduledFace)
Cross Apply (Select ScheduledFace/a.[ORIGINAL BALANCE]) CA7 (ScheduledFactor)
Cross Apply (Select 100 * (1-(b.[CURRENT FACTOR]/ScheduledFactor))) CA8(SMM)
Cross Apply (Select (1-(power(1-SMM/100,12)))*100) CA9 (CPR)

WHERE a.[CURRENT WA MATURITY] != 0 and a.[CURRENT BALANCE] != 0 and a.[CUSIP NUMBER] = '31416hag0'

查询最终会生成一个名为“CPR”的函数用于债券分析,我想将这些结果和其他列添加到永久表中。

我使用的是 SQL Server 2012。谢谢!

最佳答案

SELECT a.[CUSIP NUMBER],
...
INTO newTable
FROM DBO.mbs032013 a
...

关于SQL:使用查询结果创建新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17280816/

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