Last active
September 11, 2018 00:21
-
-
Save goodpic/233a07e1b05150a9b62e6d94a5840dc6 to your computer and use it in GitHub Desktop.
Hourly sales
This file contains hidden or 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
SELECT | |
TIMESTAMP_TRUNC(invoiced_at, HOUR) AS timestamp | |
, DATETIME_TRUNC(local_invoiced_at, HOUR) AS date_hour | |
, FORMAT_DATETIME("%A", local_invoiced_at) AS day | |
, MOD(CAST(FORMAT_DATETIME("%u", local_invoiced_at) AS int64), 7) AS day_num | |
, FORMAT_DATETIME("%H", local_invoiced_at) AS hour | |
, shop_name | |
, COUNT(*) AS transactions | |
, SUM(customers) AS customers | |
, SUM(sales) AS sales | |
, SUM(tax) AS tax | |
, SUM(cost) AS cost | |
, SUM(discount) AS discount | |
, SUM(sales - tax) AS net | |
FROM | |
PROJECT.DATASET.transactions | |
GROUP BY | |
shop_name, timestamp, date_hour, day, day_num, hour | |
ORDER BY | |
date_hour DESC | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment