Sql script for logical table


Could anyone advice on how to write a proper script in order to achieve mtd and py mtd transformational table?
I have something like that but here are some errors I think

Select A.day_date day_date, B.day_date mtd_date

From UvwDimDay A, UvwDimMonth B

Where A.day_date >= B.day_date

And MONTH(A.day_date)= MONTH(B.day_date)

select a.DtKey, b.DtKey MTD_DtKey

from UvwDimDate a

inner join UvwDimDate b

on b.MthKey = a.MthKey

and b.DtKey <= a.DtKey

I enclose a screenshot of tables

goal is to have somethng like that

I'd like to enclose somescreenshot but not sure if that possible here

Thank you

It's better if you provide table structures as data definition (DDL) CREATE TABLE statements in text form. You should similarly provide some sample data and the results you're expecting, so that we can work from the same baseline.