下面是我的数据集示例,我需要找到公司一年的平均收费率。
Date Close company
2008 49.220001 Allstate Insurance Group
2008 47.73 Allstate Insurance Group
2008 48.060001 Allstate Insurance Group
2008 50.360001 Allstate Insurance Group
2009 21.67 Allstate Insurance Group
2009 16.83 Allstate Insurance Group
2011 31.139999 Allstate Insurance Group
2011 31.780001 Allstate Insurance Group
2011 31.780001 Allstate Insurance Group
2008 42.130001 ANTHEM
2009 41.450001 ANTHEM
2009 33.919998 ANTHEM
2009 37.970001 ANTHEM
2010 48.93 ANTHEM
2010 50.720001 ANTHEM
2010 49.66 ANTHEM
2012 18.219999 AXA inaurance
2013 18.450001 AXA inaurance
2014 26.309999 AXA inaurance
2014 25.950001 AXA inaurance
现在我需要找到每家公司每年的平均价值。例如,我需要为“2008,2009,2010”每年找到“ANTHEM”的平均值。不知道如何在聚合函数中传递2个变量。
我的预期输出是:
2008 42.130001 ANTHEM
2009 37.6849995 ANTHEM
2010 49.77000033 ANTHEM
2008 48.84250075 Allstate Insurance Group
2009 19.25 Allstate Insurance Group
2011 31.566667 Allstate Insurance Group
只需使用avg()
select date,company, avg(close)
from table group by date,company