创建所有可能组合的列表 [英] Creating a list of all possible combinations
本文介绍了创建所有可能组合的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行以下操作。
I'm trying to do the following.
我想创建某些事物之间所有可能关系的列表。
I want to create a list of all possible relationships between certain things.
例如。有玛丽,爱丽丝,六月,辛迪,伊丽莎白,贝蒂,贾克斯
For example. There's Mary, Alice, June, Cindy, Elizabeth, Betty, Jax
我想为列表创建所有可能的组合:
I would like to create all possible combinations for a list like this:
- 玛丽,爱丽丝
- 玛丽,六月
- 玛丽·辛迪
- Mary,Jax
- Mary,Alice,June
- Mary,Alice,Cindy
- 玛丽,爱丽丝,伊丽莎白
... - 玛丽,爱丽丝,贾克斯
- 玛丽,六月,辛迪
- 六月,玛丽伊丽莎白
... - 六月,Jax玛丽·贾利
- 玛丽,辛迪,伊丽莎白
- 玛丽,辛迪,贝蒂
- 玛丽,辛迪,贾克斯
... - 玛丽,爱丽丝,六月,辛迪
- 玛丽,爱丽丝,六月,伊丽莎白
- 玛丽,爱丽丝,六月,贝蒂
.. - 玛丽,爱丽丝,六月,辛迪,伊丽莎白
- 玛丽,爱丽丝,六月,辛迪,贝蒂
- Mary, Alice
- Mary, June
- Mary Cindy
- Mary, Jax
- Mary, Alice, June
- Mary, Alice, Cindy
- Mary, Alice, Elizabeth ...
- Mary, Alice, Jax
- Mary, June, Cindy
- Mary, June, Elizabeth ...
- Mary, June, Jax
- Mary, Cindy, Elizabeth
- Mary, Cindy, Betty
- Mary, Cindy, Jax ...
- Mary, Alice, June, Cindy
- Mary, Alice, June, Elizabeth
- Mary, Alice, June, Betty ...
- Mary, Alice, June, Cindy, Elizabeth
- Mary, Alice, June, Cindy, Betty
有人知道一种用SQL,Access或C#做到这一点的方法吗?如果我可以在DB上使用另一种语言,我将不胜感激!
Anyone know of a way to do this in either, SQL, Access, or C#? If there's another language out there that I can use on DB's I'd appreciate it a lot!
谢谢,
maria
Thanks, maria
推荐答案
您可能喜欢许多现代数据库服务器为此使用的递归查询。
You may like recursive queries used by many modern DB servers for this.
访问权限不是一个其中:(
ACCESS is not one of them :(
以下是带有职位
postgres=# with RECURSIVE y1(b,c,d) as (
postgres(# with x1(a) as (
postgres(# values('a')
postgres(# union all
postgres(# values ('b')
postgres(# union all
postgres(# values ('c')
postgres(# union all
postgres(# values ('d')
postgres(# )
postgres(# select a,a,1
postgres(# from x1
postgres(# union all
postgres(# select a||b,a,d+1
postgres(# from x1
postgres(# join y1 on (a < c)
postgres(# )
postgres-# select *
postgres-# from y1;
b | c | d
------+---+---
a | a | 1
b | b | 1
c | c | 1
d | d | 1
ab | a | 2
ac | a | 2
ad | a | 2
bc | b | 2
bd | b | 2
cd | c | 2
abc | a | 3
abd | a | 3
acd | a | 3
bcd | b | 3
abcd | a | 4
(15 rows)
postgres=#
这篇关于创建所有可能组合的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文