SQL MAX, MIN , AVG FUNCTIONS along with GROUP BY and PARTITION BY