我想要一组给定数组中数字的所有可能组合。
我尝试使用 presto 的一些预定义函数,例如 array_agg(x)
Input : [1,2,3,4]
Output
when n=2 : [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]]
when n=3 : [[1,2,3],[1,2,4],[1,3,4],[2,3,4]]
when n=4 : [[1,2,3,4]] or [1,2,3,4]
最佳答案
有combinations(array(T), n) 功能,它完全符合您的要求:
select combinations(array[1,2,3,4],2);
关于arrays - Presto SQL - 如何获得数组的所有可能组合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56540393/