将数据合并到一列中 - sql server 2012
Merge data into one column - sql server 2012
如何将不同帐号的数据合并到一列中。目前,它看起来像这样。
TableA.Order TableA.Question TableB.Response
1 a Null
1 b James
1 c Null
2 d Zebra
2 T Null
但是,我希望它像下面这样合并:
TableA.Order NewColumn
1 a
1 b
1 c
1 James
2 d
2 T
2 Zebra
根据我对你问题的理解。我设计了一个解决方案来解决这个问题。请参阅下面的查询:
SELECT * FROM TableA
UNION ALL
SELECT B.Order1,A.Response From
(
(SELECT ROW_NUMBER()OVER(ORDER BY Response)PK,* FROM TableB) A Left Join
(SELECT ROW_NUMBER()OVER(ORDER BY Order1)PK,* FROM TableA) B On A.PK=B.PK
)
Where Response IS NOT NULL
如何将不同帐号的数据合并到一列中。目前,它看起来像这样。
TableA.Order TableA.Question TableB.Response
1 a Null
1 b James
1 c Null
2 d Zebra
2 T Null
但是,我希望它像下面这样合并:
TableA.Order NewColumn
1 a
1 b
1 c
1 James
2 d
2 T
2 Zebra
根据我对你问题的理解。我设计了一个解决方案来解决这个问题。请参阅下面的查询:
SELECT * FROM TableA
UNION ALL
SELECT B.Order1,A.Response From
(
(SELECT ROW_NUMBER()OVER(ORDER BY Response)PK,* FROM TableB) A Left Join
(SELECT ROW_NUMBER()OVER(ORDER BY Order1)PK,* FROM TableA) B On A.PK=B.PK
)
Where Response IS NOT NULL