sqlgoogle-bigquerybq

List of Months with Years


How can I simply get a list of months with years without a field? Kind of like how we do current_date() but instead a list of month_years to date in SQL/Big Query


Solution

  • You can unnest a date array:

    select yyyymm
    from unnest(generate_date_array(date '2020-01-01', '2020-12-01', interval 1 month)) yyyymm