WITH MonthlyData AS (
SELECT
store_id,
CONCAT(months_date, '-01') AS months_date, -- Assuming the first day of the month
SUM(monthly_revenue) AS monthly_revenue
FROM
monthly_revenue
GROUP BY
store_id, months_date
)
SELECT
store_id,
months_date,
monthly_revenue,
monthly_revenue / first_month_revenue AS standardized_revenue
FROM (
SELECT
md.store_id,
md.months_date,
md.monthly_revenue,
FIRST_VALUE(md.monthly_revenue) OVER (PARTITION BY md.store_id ORDER BY md.months_date) AS first_month_revenue
FROM
MonthlyData md
) AS subquery
ORDER BY
store_id, months_date;