SELECT
DISTINCT billing_country country,
COUNT(DISTINCT invoice_id) total_invoice,
total_customer
FROM invoice i
JOIN(SELECT country,
COUNT(customer_id) total_customer
FROM client
GROUP BY country) AS customer_country ON customer_country.country=i.billing_country
WHERE EXTRACT(YEAR FROM CAST(invoice_date AS DATE)) =
(SELECT year_number
FROM (SELECT EXTRACT(YEAR FROM CAST(invoice_date AS DATE)) year_number,
EXTRACT(MONTH FROM CAST(invoice_date AS DATE)) month_number,
SUM(total) AS sum_total
FROM invoice
WHERE EXTRACT(MONTH FROM CAST(invoice_date AS DATE)) BETWEEN 6 AND 8
GROUP BY year_number, month_number) AS yms
GROUP BY year_number
ORDER BY SUM(sum_total) DESC
LIMIT 1)
GROUP BY billing_country, total_customer
ORDER BY total_invoice DESC, country ASC