with t1 as (select a.product_id product_id,product_name,sale_month,quantity from sales_underline a join products_underline b on a.product_id = b.product_id where substring(sale_month,7,1) between 1 and 6) select product_id,product_name, sum(quantity) as total_sales, max(quantity) as max_monthly_sales, min(quantity) as min_monthly_sales, round(avg(quantity),0) as avg_monthly_sales from t1 group by product_id,product_name order by product_id