我创建了这个sql DEMO:
我有 #tbl1 :
___cola__
1
2
3
4
和 #tbl2 :
_colb_
a
b
c
d
我要这个 :
_colb____|__cola____
a 1
b 2
c 3
d 4
我找到了解决方案(恕我直言)
SELECT table1.cola, table2.colb FROM
(SELECT cola, ROW_NUMBER() OVER (ORDER BY cola) AS rn1 FROM #tbl1) table1,
(SELECT colb, ROW_NUMBER() OVER (ORDER BY colb) AS rn2 FROM #tbl2) table2
WHERE table1.rn1 = table2.rn2
对于知识,我还能怎么做?
我从:
SELECT cola , s.f FROM #tbl1 cross apply(select colb as f from #tbl2) s
但是右边的部分有问题。