本文介绍了在SQL Server中水平构造数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好我有一个查询返回如下数据 选择n.Key,np.value来自Test1 np join Test2 n on n.Key = np。密钥,其中n.NodeKey = 10000002&& np.pKey in(4,6,7,10,12) 返回如下数据 键值 -------- ------ 10000002 2 10000002 0 10000002 2 10000002真 10000002 1 Test2查找表如下 关键PKey值 ------------------------ --------------- 10000002 4 2 10000002 6 0 10000002 7 2 10000002 10真 10000002 12 1 想要更改查询,以便它返回如下数据 NodeKey Value1 Value2 Value3 Value4 Value5 ------------------------------------------------ - 10000002 2 0 2真1 能帮忙吗我有这个。 我尝试了什么: 尝试重组查询,以便它水平返回数据Hi I have a query which returns data as belowselect n.Key, np.value from Test1 np join Test2 n on n.Key = np.Key where n.NodeKey = 10000002 && np.pKey in (4,6,7,10,12)which returns data as belowKey value-------- ------10000002 210000002 010000002 210000002 True10000002 1Test2 is look up Table as below Key PKey Value---------------------------------------10000002 4 210000002 6 010000002 7 210000002 10 True10000002 12 1Wanted to change the query so that it should return data as belowNodeKey Value1 Value2 Value3 Value4 Value5--------------------------------------------------10000002 2 0 2 True 1Can you please help me with this.What I have tried:Tried restructuring the query so that it returns data horizontally推荐答案请看这里:使用PIVOT和UNPIVOT | Microsoft Docs [ ^ ] 这篇关于在SQL Server中水平构造数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 16:24