gpt4 book ai didi

sql-server - 生成 tsql 色号排列

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:24:22 26 4
gpt4 key购买 nike

我有这个示例表:

CREATE TABLE Balls 
(
BallId int primary key identity(1,1) NOT NULL,
Color char(1) NOT NULL,
Number int NOT NULL
)

我有不同颜色的球,每个球上都有一个数字。表中数据示例:

BallId  Color   Number
4 G 1
9 G 2
1 R 1
2 R 2
3 R 3
5 W 1
6 W 2
7 W 3
8 W 4

我需要所有不同球的所有排列(在本例中为 G-R 和 W)以及数字。例如:

G1 R1 W1
G1 R1 W2
G1 R1 W3
G1 R1 W4
G1 R2 W1
...
G2 R3 W4

“G1 R1 W1”等于“R1 G1 W1”(顺序无关紧要)。我需要 tsql 脚本来生成这个排列。提前致谢!

最佳答案

除非您采取措施限制结果,否则连接表将产生排列。

select g.color, g.number, r.color, r.number, w.color, w.number

from Balls g, Balls r, Balls w
where g.color = 'G'
and r.color = 'R'
and w.color = 'W'

关于sql-server - 生成 tsql 色号排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20975366/

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