Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL生成同一表上的组项之间的所有可能组合_Sql_Sql Server_Tsql_Combinations - Fatal编程技术网

SQL生成同一表上的组项之间的所有可能组合

SQL生成同一表上的组项之间的所有可能组合,sql,sql-server,tsql,combinations,Sql,Sql Server,Tsql,Combinations,我有一个SQL表,我想生成组之间的所有组合 组合本身将不包括在内 我的代码: 预期结果如下所示 我已尝试使用交叉和完全外部联接,但无法执行此操作。您应该可以使用交叉应用来执行此操作,例如: 选择[CombinationID]=identityint、1、1、GroupID、ID 进入tmp_组_项目 从值1、2、3到aGroupID 交叉应用值1、2、3投标; 从tmp_组_项中选择*; 这将产生: CombinationID GroupID ID 1

我有一个SQL表,我想生成组之间的所有组合

组合本身将不包括在内

我的代码:

预期结果如下所示


我已尝试使用交叉和完全外部联接,但无法执行此操作。

您应该可以使用交叉应用来执行此操作,例如:

选择[CombinationID]=identityint、1、1、GroupID、ID 进入tmp_组_项目 从值1、2、3到aGroupID 交叉应用值1、2、3投标; 从tmp_组_项中选择*; 这将产生:

CombinationID   GroupID ID
            1         1  1
            2         1  2
            3         1  3
            4         2  1
            5         2  2
            6         2  3
            7         3  1
            8         3  2
            9         3  3

您的输入是什么?您所说的“组之间的所有组合”是什么意思?请告诉我们您尝试了什么。我尝试了交叉连接本身从tmp_组_项目c1中选择*交叉连接tmp_组_项目c2

CombinationID   GroupID ID
-------------   ------- --
1               1       1
1               2       1
1               3       1
2               1       1
2               2       1
2               3       2
3               1       1
3               2       1
3               3       3

4               1       2
4               2       1
4               3       1
5               1       2
5               2       1
5               3       2
6               1       2
6               2       1
6               3       3

7               1       3
7               2       1
7               3       1
8               1       3
8               2       1
8               3       2
9               1       3
9               2       1
9               3       3
...
CombinationID   GroupID ID
            1         1  1
            2         1  2
            3         1  3
            4         2  1
            5         2  2
            6         2  3
            7         3  1
            8         3  2
            9         3  3