Oracle OrderBy匹配互补值
我有一张具有以下内容
ID | 名称 | 的表ID |
---|---|---|
1包 | a | 3 |
2 | 包B | 2 |
3 | 包C | 1 |
4 | 包D | 2 |
5 | Package E | 5 |
现在我想订购它们,以便两个直接连续的软件包的总和应与值“ 4”。
在上表的情况下,正确的结果可能会如下:
ID | 名称 | 件包 |
---|---|---|
1 | a | 3 |
2 | 软件包 | 1 |
3 | 包b | 2 |
4 | 包D | 2 |
5 2 | 5包e | 5 |
我的问题是,使用Oracle SQL功能和如果是这样,有人会如何意识到这一点?
I have a table with the following content
ID | NAME | SIZE |
---|---|---|
1 | PACKAGE A | 3 |
2 | PACKAGE B | 2 |
3 | PACKAGE C | 1 |
4 | PACKAGE D | 2 |
5 | PACKAGE E | 5 |
Now i would like to order them so that the sum of two directly successive packages shall correspond to the value '4'.
In the case of the table above a right result could look like this:
ID | NAME | SIZE |
---|---|---|
1 | PACKAGE A | 3 |
2 | PACKAGE C | 1 |
3 | PACKAGE B | 2 |
4 | PACKAGE D | 2 |
5 | PACKAGE E | 5 |
My question is if this is possible with Oracle SQL functions and if so how someone would realise this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建
管道
功能以获取对。首先创建类型:
然后函数:
对于示例数据:
以最小的大小和相应对开始,然后以增加尺寸的对开始,以排序输出行。如果发现没有匹配对的行,则立即输出,发现没有对。
db< = 74928BF944781459CF1D62E0E0F5AF51“ rel =“ nofollow noreferrer”>此处
You can create a
PIPELINED
function to get the pairs.First create the types:
And then the function:
Which, for the sample data:
Outputs the rows in the order starting from the smallest size and the corresponding pair and then in increasing sized pairs. If a row is found that does not have a matching pair then it is output immediately it is found not to have a pair.
db<>fiddle here