Snowflake SQL - 将 mmddyyyy 转换为 mmyyyy,然后按 mmyyyy 分组

Snowflake SQL - convert mmddyyyy to mmyyyy and then group by mmyyyy

在雪花中工作sql。我有一个日期字段,它是 mm-dd-yyyy。我想将其转换为 mm-yyyy,然后将其余查询分组到 mm-yyyy 级别。

我有:

select
    SFDC_ACCOUNT_KEY,
    date_trunc('month',DATE_CURRENT) as mm_yyyy,
    max(ACTIVE_COMMERCIAL_UNITS) as max_active_commercial_units,
    max(ACTIVE_HOA_UNITS) as max_active_hoa_units,
    max(ACTIVE_RESIDENTIAL_UNITS) as max_active_res_units,
    max(TOTAL_ACTIVE_UNITS) as max_total_active_units
FROM SHARED.CUSTOMERS_DIM
group by sfdc_account_key, date_current
order by sfdc_account_key, date_current;

因为原始日期是mm-dd-yyyy,所以当我想要它包装在 mm-yyyy 级别。

这让我抓狂,因为我确信它很简单,但已经晚了,我很困惑。

如有任何帮助,我们将不胜感激。

在分组依据

中使用date_trunc('month',DATE_CURRENT)而不是date_current
select
    SFDC_ACCOUNT_KEY,
    date_trunc('month',DATE_CURRENT) as mm_yyyy,
    max(ACTIVE_COMMERCIAL_UNITS) as max_active_commercial_units,
    max(ACTIVE_HOA_UNITS) as max_active_hoa_units,
    max(ACTIVE_RESIDENTIAL_UNITS) as max_active_res_units,
    max(TOTAL_ACTIVE_UNITS) as max_total_active_units
FROM SHARED.CUSTOMERS_DIM
group by sfdc_account_key, date_trunc('month',DATE_CURRENT)
order by sfdc_account_key, date_trunc('month',DATE_CURRENT)