如何在SQL中合并2列与所有可能的组合?

Roc*_*etq 2 sql merge combinations ansi-sql

这个问题听起来令人困惑,但看看:

这样我们就可以获得第一列(col1):

select distinct maker
from product
Run Code Online (Sandbox Code Playgroud)

第二列(col2):

select distinct type,maker
from product
Run Code Online (Sandbox Code Playgroud)

所以现在我需要从col1和col2获得所有可能的组合.有什么建议吗?

不久,这个:

A f1

B f2
Run Code Online (Sandbox Code Playgroud)

应该成为这样的:

A f1

A f2

B f1

B f2
Run Code Online (Sandbox Code Playgroud)

PS此查询不会返回我需要的内容.

select distinct A.maker, B.type
from product as A
Run Code Online (Sandbox Code Playgroud)

Gor*_*off 6

使用cross join得到所有组合:

select m.maker, t.type
from (select distinct maker from product) m cross join
     (select distinct type from product) t;
Run Code Online (Sandbox Code Playgroud)

这是ANSI SQL语法,应该在任何数据库中都受支持.