SELECT order_id,
CAST(DATE_TRUNC('month', created_at) AS date) AS date_month,
total_amt,
COUNT(order_id) OVER (ORDER BY CAST(DATE_TRUNC('month', created_at) AS date)) AS order_count,
SUM(total_amt) OVER (ORDER BY CAST(DATE_TRUNC('month', created_at) AS date))
FROM tools_shop.orders
ORDER BY date_month
WINDOW. Вспомните, в какой части запроса указывают конструкцию.