作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题听起来很困惑,但看看:
这样我们就可以得到第一列(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/
我是一名优秀的程序员,十分优秀!