为每个表中的每一行获取一个行号,然后使用这些行号进行完全连接:
WITH CTE1 AS( SELECt ROW_NUMBER() OVER(ORDER BY col1) AS ROWNUM, * FROM Table1),CTE2 AS( SELECt ROW_NUMBER() OVER (ORDER BY mycol1) AS ROWNUM, * FROM Table2)SELECt col1, col2, mycol1, mycol2FROM CTE1 FULL JOIN CTE2 ON CTE1.ROWNUM = CTE2.ROWNUM
这是假定SQL Server> = 2005。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)