抱歉,我又发布了一项要求。
任何人都可以帮忙吗:我试图加入重复的值,但并没有达到我想要的水平。
[No],[Desc],[Value1],[Value2],[MatchResult]
,(N'123953',N'Extra Pay',300.02,200.02, False)
,(N'123953',N'Basic Hours',427.2,427.2, True)
,(N'123953',N'Basic Hours',106.8,106.8, True)
,(N'123953',N'Basic Hours',213.6,213.6, True)
,(N'123953',N'Basic Hours',213.6,213.6, True)
,(N'123953',N'Basic Hours',213.6,213.6, True)
,(N'123953',N'Basic Hours',213.6,NULL,NULL)
,(N'123953',N'Basic Hours',105.6,105.6, True)
所需的输出:
responseJson[AuthUtils.authTokenKey]
答案 0 :(得分:0)
-在我看来,您应该能够将row_numbers强制复制到重复的行上,从而实现一对一的连接,右边没有匹配项为null
SELECT Q1.No, Q1.[desc], Q1.[value1],q2.[value2] FROM
(SELECT [NO] ,
value1,
[desc],
ROW_NUMBER() over(partition by [NO] , value1, [desc] order by [no]) RN
FROM #TestTable1
) Q1
LEFT JOIN
(SELECT [NO] ,
value2,
[desc],
ROW_NUMBER() over(partition by [NO] , value2, [desc] order by [no]) RN
FROM #TestTable2
) Q2
ON Q1.Value1=Q2.Value2 AND
Q1.[No] = Q2.[NO] AND
Q1.[desc] = Q2.[Desc] AND
Q1.RN = Q2.rn