sql server 2008中percentile_cont的替代方案
在 Oracle 中,它运行良好......
Oracle 的查询如下,
Select distinct channel_id, position_id,datamonth,
percentile_cont(.9) within group (order by TRIM_PRE_ELIG_PAY)
over (partition by channel_id, position_id, datamonth) as TRIM_PRE_ELIG_PAY_90th_PERC
from Tablename
但对于 SQL Server,我收到错误。以下是 SQL Server 2008 的查询:
Select
distinct channel_id,
position_id, datamonth,
percentile_cont(.9) within group (order by TRIM_PRE_ELIG_PAY)
over (partition by channel_id) as TRIM_PRE_ELIG_PAY_90th_PERC
from table
错误:无法正确解析选择。输出无法 生成。
我知道它可以在 SQL Server 2012 中正常工作,但在 SQL Server 2008 中需要替代方法
任何人都可以帮忙...........
In Oracle it works well ......
Query for oracle is As Follows
Select distinct channel_id, position_id,datamonth,
percentile_cont(.9) within group (order by TRIM_PRE_ELIG_PAY)
over (partition by channel_id, position_id, datamonth) as TRIM_PRE_ELIG_PAY_90th_PERC
from Tablename
But for SQL Server, I'm getting an error. Here's the query for SQL Server 2008:
Select
distinct channel_id,
position_id, datamonth,
percentile_cont(.9) within group (order by TRIM_PRE_ELIG_PAY)
over (partition by channel_id) as TRIM_PRE_ELIG_PAY_90th_PERC
from table
ERROR: Select could not be parsed correctly. Output could not be
generated.
I got to know that it can work properly in SQL Server 2012 but need an alternative way in SQL Server 2008
Can anybody help...........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQL Server Engine 博客 适用于 SQL Server 2005+
不幸的是,它相当长且令人费解:我将给您留下链接,而不是尝试根据您的查询调整它...
There is a workaround on the SQL Server Engine blog that applies to SQL Server 2005+
Unfortunately, it's quite long and convoluted: I'll leave you with the link rather than attempt to adapt it for your query...
您可以创建一个 CLR 聚合函数来实现相同的功能。唯一的缺点是您将不得不重新安排查询。我使用 CLR 实现了percentile_cont。请阅读此处了解如何创建CLR。然后你可以使用此代码获得与percentile_cont相同的O/P。它比编写多个语句容易得多。
您绝对可以根据您的使用情况对其进行一些改进/调整。
You can create a CLR Aggregate function to implement the same. The only downfall is that you will have to re-arrange your query a bit. I implemented the percentile_cont using the CLR. Read here on how to create the CLR . Then you can use this code to get the same O/P as percentile_cont. Its a lot more easier than writing multiple statements.
You can definitely refine/tweak it a bit depending on your usage.