Array combinations without repetition

不打扰是莪最后的温柔 提交于 2019-11-28 01:47:08

问题


I would like to make combinations out from an int[]

{2,4,6,7,8,10,13,15,16,18} should give following results:

2,4,6
2,4,7
2,4,8
...
15,16,18

Is it possible to write query only solution without using custom functions?


回答1:


with a as (
    select i
    from unnest (array[2,4,6,7,8,10,13,15,16,18]) s(i)
)
select *
from
    a cross join a b cross join a c
where
    a < b and b < c
order by a, b, c


来源:https://stackoverflow.com/questions/16899760/array-combinations-without-repetition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!