gpt4 book ai didi

sql-server - 如何使用 NTILE 函数更新表中的值?

转载 作者:行者123 更新时间:2023-12-01 06:17:08 29 4
gpt4 key购买 nike

摘要:我正在尝试按前五分位数和后五分位数对这些股票因素进行排名,以构建多头/空头投资组合。

表:

enter image description here

期望的结果:

enter image description here

使用的代码:

UPDATE MOMENTUM_Quintile 
SET [2006-12-30] = NTILE(5) OVER (ORDER BY [2006-12-30] DESC)
FROM MOMENTUM_Quintile

错误信息:

Msg 4108, Level 15, State 1, Line 7
Windowed functions can only appear in the SELECT or ORDER BY clauses.

最佳答案

错误很明显,你不能这样做的原因,与逻辑查询处理有关。你可以在下面尝试

 With cte
as(
select *, NTILE(5) OVER (order by [2006-12-30] desc) as ntile
from
MOMENTUM_Quintile
)
update cte
set [2006-12-30]=ntile

关于sql-server - 如何使用 NTILE 函数更新表中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42398239/

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