0
votes

I have just started exploring Snowflake and was trying to create my first view.

And I am getting the below syntax error on grouping. Can anyone guide me here what am I missing?

create or replace view MyView_V1 as 
    select     sum(NUMBER_OF_RECORDS) as total_records, 
               date_part(month, "DATE") as extracted_month, 
               date_part(week, "DATE") as  extracted_week, 
    from        "MV_DB"."MV_SCHEMA"."MV_TABLE",
    group by     extracted_month, extracted_week, 
    order by     extracted_month asc,extracted_week asc;

Error : SQL compilation error: syntax error line 6 at position 0 unexpected 'from'. syntax error line 7 at position 0 unexpected 'group'. syntax error line 8 at position 0 unexpected 'order'.

Thank you, Akshat

1
You have a comma before the FROM.Gordon Linoff
Thank you! @GordonLinoff, it workedAkshat3990

1 Answers

1
votes

Please remove the comma before the from clause and execute the query.

    create or replace view MyView_V1 as 
        select     sum(NUMBER_OF_RECORDS) as total_records, 
                   date_part(month, "DATE") as extracted_month, 
                   date_part(week, "DATE") as  extracted_week
        from        "MV_DB"."MV_SCHEMA"."MV_TABLE"
        group by     extracted_month, extracted_week
        order by     extracted_month asc,extracted_week asc;