sql - Return distinct rows after averaging on group -
i have table mytable
looks
periodenddate tottermloans companyname 2009-09-30 na abb 2009-09-30 5.38 abb 2009-09-30 4.34 abb 2009-12-31 5.6 abb 2009-12-31 5.6 abb 2009-12-31 5.6 abb 2010-03-31 5.47 abb 2010-03-31 5.47 abb 2010-03-31 5.0 abb
i wish group year , average of tottermloans
each year, query repeated rows:
select year(periodenddate), avg(tottermloans), companyname mytable group year(periodenddate)
which gives
year(periodenddate) avg(tottermloans) companyname 2009 5.304 abb 2009 5.304 abb 2009 5.304 abb 2010 5.313 abb 2010 5.313 abb 2010 5.313 abb
i like
year(periodenddate) avg(tottermloans) companyname 2009 5.304 abb 2010 5.313 abb
do have use sub queries this? thank you
select year(periodenddate), avg(tottermloans), companyname mytable group year(periodenddate), companyname
the distinct
keyword can used on select
statements remove duplicated results.
Comments
Post a Comment