change query for bottom chart to gather the average data from db