postgresql (Postgres) row_number OVER 8.2 中的分区
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1686528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
(Postgres) row_number OVER Partition in 8.2
提问by KB22
some time ago I happend to resolve a PG related problem with this SO question of mine. Basically it's about using row_number over a partition in 8.4.
前段时间我碰巧用我的这个 SO 问题解决了一个与 PG 相关的问题。基本上它是关于在 8.4 中的分区上使用 row_number。
Sadly now I have to create the same thing for 8.2 since one of my customers is on 8.2 and needs it desperatly.
可悲的是,现在我必须为 8.2 创建相同的东西,因为我的一位客户使用 8.2 并且非常需要它。
What I do know (on 8.4) is the following:
我所知道的(在 8.4 上)如下:
SELECT custId, custName, 'xyz-' || row_number() OVER (PARTITION by custId)
AS custCode
Basically counting the occurances of custId and assigning custCodes from that. (just an example, to show what I to; of course the query is way more complex)
基本上计算 custId 的出现并从中分配 custCodes。(只是一个例子,以显示我要做什么;当然查询要复杂得多)
I figured the solutions provided to the question mentioned above, but did'nt get them working since there's one more hurdle to take. I don't run SQL directly I have to embed it into a xml based config file which creates a certain xml format from the query results. So creating temp stuff or procedures is not really an option.
我想出了为上述问题提供的解决方案,但没有让它们工作,因为还有一个障碍需要克服。我不直接运行 SQL 我必须将它嵌入到基于 xml 的配置文件中,该文件根据查询结果创建某种 xml 格式。所以创建临时的东西或程序并不是一个真正的选择。
So here's the question, does anyone of you guys have an idea how to port that solution of mine to PG 8.2?
那么问题来了,你们中有人知道如何将我的解决方案移植到 PG 8.2 吗?
TIA
TIA
K
钾