I've got a large database that's got all our transactions and shipping costs from them, here's a simplified version:
Source Table
Here is a possible way of doing it by using PIVOT in Snowflake: https://docs.snowflake.com/en/sql-reference/constructs/pivot.html
Let's say "monthname" is a column you extracted out of your "Date"-column, probably this helps:
select * from yourTable pivot(sum(cost) for monthname in ('January', 'February', 'March', 'April')) order by route;
The values of your monthname-column should match the one in the brackets.
As this is a more static solution, you still have to adjust the code every month. Here probably writing a stored procedure is helping: https://docs.snowflake.com/en/sql-reference/stored-procedures.html
1.4m articles
1.4m replys
5 comments
57.0k users