SQL - 将不同数量的行与匹配ID结合起来
问题描述:
我需要组合多行。
每一行作为一个ID和一个子ID。
ID标识用户,Sub ID标识合同期限。我需要结合基于这些行抢等栏目SQL - 将不同数量的行与匹配ID结合起来
例
ID SubID StartDate StartVal EndDate
123456 1 37622 100 37686
123456 2 37781 20 37782
254896 22 38584 44 38658
254896 23 38722 18 38766
254896 24 38825 6 38890
254896 25 38972 68 39011
365897 1 39696 38 41191
和我的目标
ID StartDate1 StartVal1 EndDate1 EndValue1 StartDate2 StartVal2 EndDate2 EndValue2....
123456 37622 100 37686 26 37781 20 37782 65
254896 38584 44 38658 59 38722 18 38766 20....
365897 39696 38 41191 71
或
ID StartDate StartVal EndDate EndValue
123456 37622,37688 81,8 37637,37722 12,90
254896 38584,38740,38796,38836 98,22,68,10 38670,38788,38796,38925 6,10,31,57
365897 39696 7 41191 74
有什么建议?在先进的感谢,萨姆
答
您可以使用加入这个:
Select * from USER join ContactPeriod ON User."some common attribute of both tables" ="Contact.that attribute"
我的建议是谷歌'SQL动态PIVOT多个columns' –
好的,谢谢。我会看一下。 – bms45
您正在使用哪个[DBMS](https://en.wikipedia.org/wiki/DBMS)产品? Postgres的?甲骨文? –