I spent some hours searching and coding but i am not able to find a solution. I have a table with dates (format yyyy-mm-dd) and payment value. Each row after agregating has only one date e related values. I need generate a resultset with the folowing format: [date] [value from current date] [value from date exact last year] [value from same day from last month]
Anyone could help me? My DB is BigQuery.
`--Didn't work select current.date, previous.date --extract(year from previous.date) -1
from
f_table.agg
current left joinf_table.agg
previous on extract(day from current.date) = extract(day from previous.date) and (extract(month from current.date) = extract(month from previous.date) and extract(year from current.date) = (extract(year from previous.date) - 1) )`
--Didn't work select current.date, sum(current.value) --lag( sum(current.value), 1) over (order by extract(year from current.date))
from
f_table.agg
currentgroup by current.date order by current.date desc