如何在SQL Server 2008中以年为基础加入数据 [英] How to club data on the bases of year in SQL server 2008
本文介绍了如何在SQL Server 2008中以年为基础加入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
iyear nu_jan nu_feb nu_mar nu_apr nu_may nu_jun nu_jul nu_aug nu_sep nu_oct nu_nov nu_dec
2016 NULL NULL NULL 0.2 NULL NULL NULL NULL NULL NULL NULL NULL
2016 NULL NULL NULL NULL 0.34 NULL NULL NULL NULL NULL NULL NULL
2016 NULL NULL NULL NULL NULL 0.34 NULL NULL NULL NULL NULL NULL
2016 NULL NULL NULL NULL NULL NULL NULL NULL 2.76 NULL NULL NULL
2016 NULL NULL NULL NULL NULL NULL NULL 2.04 NULL NULL NULL NULL
2016 NULL NULL NULL NULL NULL NULL NULL NULL NULL 2.1 NULL NULL
2016 NULL NULL NULL NULL NULL NULL 1.62 NULL NULL NULL NULL NULL
2016 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2.1
2016 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 2.14 NULL
i想要这样的结果
i want result like this
iyear nu_jan nu_feb nu_mar nu_apr nu_may nu_jun nu_jul nu_aug nu_sep nu_oct nu_nov nu_dec
2016 NULL NULL NULL 0.2 .34 .34 1.62 2.04 2.76 2.1 2.14 2.1
我尝试过:
i试图做
What I have tried:
i have tried to do
PIVOT
。但它不起作用
推荐答案
只需按年份分组并显示MAX:
Just GROUP by year and show the MAX:
SELECT iYear, MAX(nu_jan), MAX(nu_Feb), ...
FROM MyTable
GROUP BY iYear
这篇关于如何在SQL Server 2008中以年为基础加入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文