您将数据 UNPIVOT 放入一列,然后 CROSS JOIN 五次。这是一个 SQL Fiddle 排列 5 列选择
3. SQL Fiddle
DECLARE @t TABLE (Field1 INT, Field2 INT, Field3 INT, Field4 INT, Field5 INT)INSERT INTO @t VALUES (1,2,3,4,5); WITH cte AS ( SELECt u.FieldValue FROM @t UNPIVOT ( [FieldValue] FOR [FieldName] IN ( Field1, Field2, Field3, Field4, Field5 ) ) u)SELECt t1.FieldValue AS PermuteField1, t2.FieldValue AS PermuteField2, t3.FieldValue AS PermuteField3FROM cte AS t1 CROSS JOIN cte AS t2 CROSS JOIN cte AS t3WHERe t1.FieldValue <> t2.FieldValue AND t1.FieldValue <> t3.FieldValue AND t2.FieldValue <> t3.FieldValue



