【问题标题】:Array combinations without repetition无重复的数组组合
【发布时间】:2013-06-03 14:59:18
【问题描述】:

我想从int[] 中进行组合

{2,4,6,7,8,10,13,15,16,18} 应该给出以下结果:

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

是否可以在不使用自定义函数的情况下编写仅查询解决方案?

【问题讨论】:

    标签: sql postgresql combinatorics


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      • 2021-09-10
      • 2019-01-05
      相关资源
      最近更新 更多