下面的SQL
with t as (
select Id
from IA
INNER JOIN IAD ON IAD.PKEY = IA.DID
LEFT JOIN IAC ON IAC.INS = IA.INS
)
select Id,
ntile((select count(*) from t) / 5000) over ( order by Id ) NT
from t;
在Oracle中运行时出现以下错误。
ORA-30488: argument should be a function of expressions in PARTITION BY 30488. 00000 - "argument should be a function of expressions in PARTITION BY" *Cause: The argument of the window function should be a constant for a partition. *Action: Error at Line: 66 Column: 20
How to assign the parameter of NTile
with computed value? I will need the code be able to be run in SQL Server via linked server.
-- SQL Server
select * from openquery(oracledb, '....the code above...')
最佳答案
函数中对“参数应该是 PARTITION BY 中表达式的函数”的要求有点奇怪。 类似这样的事情:
with t as (
select Id,
trunc ( count(*) over () / 500) as cnt
from IA
INNER JOIN IAD ON IAD.PKEY = IA.DID
LEFT JOIN IAC ON IAC.INS = IA.INS
)
select Id,
ntile(cnt ) over (partition by cnt order by Id ) NT
from t;
关于sql-server - 窗口函数的参数应该是分区常量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46577377/