avg calculated by sql