如何根据他们的ID和财政年度来衡量价值观

时间:2014-04-09 11:57:48

标签: sql sql-server sql-server-2008

我在这样的表格中有数据

ID FY1 INT1 FY2 INT2 FY3 INT3
_ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __

1 2013 - 2014 9167 2014 - 2015 1183 2015 - 2016 3002
1 2013 - 2014 10744 2014 - 2015 1345 2015 - 2016 2709
1 2014 - 2015 1758 2015 - 2016 2347

我希望在与特定ID相对应的FY匹配中加入兴趣。

我希望我的数据格式如下所示**

** ID FY1 INT1 FY2 INT2 FY3 INT3信息

_ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __

1 2013 - 2014 19911 2014 - 2015 4286 2015 - 2016 8058

1 个答案:

答案 0 :(得分:1)

SELECT id,fy1,SUM(int1) as int1,fy2,SUM(int2) as int2,fy3,SUM(int3) as int3
FROM tablename
GROUP BY id,fy1,fy2,fy3