[英]SQL - Adding each value to every other value in a table
I have a sample table我有一个示例表
table
2
4
6
I want to add each value to every other value in this manner:我想以这种方式将每个值添加到每个其他值:
table
(2+2)
(2+4)
(2+6)
(4+2)
(4+4)
(4+6)
(6+2)
(6+4)
(6+6)
The end result should look like:最终结果应如下所示:
table
4
6
8
6
8
10
8
10
12
But I have no idea on how to calculate all the values in this manner.但我不知道如何以这种方式计算所有值。
Do a self CROSS JOIN
to get a cross product:做一个 self
CROSS JOIN
得到一个交叉产品:
select t1.c + t2.c
from tablename t1 cross join tablename t2
Add ORDER BY
if you need to guarantee that specific order:如果您需要保证特定顺序,请添加
ORDER BY
:
ORDER BY t1.c, t2.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.