This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://stackoverflow.com/questions/41707583/get-total-no-of-days-in-given-month-in-google-bigquery | |
CREATE TEMP FUNCTION DaysInMonth(d TIMESTAMP) AS ( | |
32 - EXTRACT(DAY FROM DATE_ADD(DATE_TRUNC(CAST (d AS DATE), MONTH), INTERVAL 31 DAY)) | |
); | |
WITH monthly_cost_table AS (SELECT | |
account_name, | |
EXTRACT (MONTH FROM bill_datetime) month, | |
EXTRACT (YEAR FROM bill_datetime) year, | |
SUM(cost) monthly_cost |
NewerOlder