gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 09:22:02 34 4
gpt4 key购买 nike

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

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

select distinct maker
from product

第二列 (col2):

select distinct type,maker
from product

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

很快,这个:

A f1

B f2

应该变成这样:

A f1

A f2

B f1

B f2

附言此查询不会返回我需要的结果。

select distinct A.maker, B.type
from product as A

最佳答案

使用cross join获取所有组合:

select m.maker, t.type
from (select distinct maker from product) m cross join
(select distinct type from product) t;

这是 ANSI SQL 语法,任何数据库都应该支持。

关于sql - 如何将 2 列与 SQL 中所有可能的组合合并?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29276851/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com