Skip to content

Instantly share code, notes, and snippets.

@x
Created February 9, 2024 23:47
Show Gist options
  • Select an option

  • Save x/74c0cfc396ede7aa1c23763f6481d7ca to your computer and use it in GitHub Desktop.

Select an option

Save x/74c0cfc396ede7aa1c23763f6481d7ca to your computer and use it in GitHub Desktop.
CREATE TABLE tbl AS SELECT strptime(dt_iso, '%x %X %z %Z') AS dt, temp_min, temp, temp_max, feels_like FROM "nyc_weather.csv";
CREATE TABLE averages AS SELECT date_part('month', dt) AS month, date_part('day', dt) AS day, date_part('hour', dt) AS hour, avg(temp_min), avg(temp), avg(temp_max), avg(feels_like) FROM tbl GROUP BY month, day, hour ORDER BY month, day, hour;
SELECT * FROM averages WHERE month = 2 AND day = 9;
┌───────┬───────┬───────┬────────────────────┬────────────────────┬────────────────────┬────────────────────┐
│ month │ day │ hour │ avg(temp_min) │ avg("temp") │ avg(temp_max) │ avg(feels_like) │
│ int64 │ int64 │ int64 │ double │ double │ double │ double │
├───────┼───────┼───────┼────────────────────┼────────────────────┼────────────────────┼────────────────────┤
29028.44145833333333329.8833333333333331.29687500000000420.9225
29127.85955555555555229.60155555555555331.3171111111111120.02777777777778
29227.72956521739130429.2797826086956530.63804347826087220.333695652173915
29327.14200000000000328.7930.33688888888888619.754444444444445
29426.9953191489361728.81276595744680330.3825531914893619.206808510638297
29526.0119148936170227.7480851063829829.31531914893617218.446170212765956
29626.20916666666666527.80104166666666329.357518.303749999999997
29725.833191489361727.76978723404255329.3161702127659618.10936170212766
29826.28638297872340627.9387234042553229.51914893617021518.330638297872337
29927.87104166666666729.2870833333333430.65666666666666619.46291666666667
291029.55312499999999831.04958333333333432.3322916666666721.766041666666666
291130.6026530612244931.82530612244898233.2248979591836722.968775510204082
291232.2072916666666733.5916666666666734.9345833333333324.942708333333332
291333.20604166666666434.70479166666666536.2412526.054791666666663
291433.87478260869565435.24195652173913436.8602173913043527.05217391304348
291534.83636.11777777777777537.6095555555555528.226000000000003
291634.6104255319148935.9980851063829737.5751063829787227.544468085106384
291732.813617021276634.18957446808510536.06638297872340426.24489361702128
291832.6902272727272734.0259090909090935.9468181818181825.695909090909087
291932.2017777777777733.5164444444444435.1753333333333325.302222222222227
292031.85533333333333433.3173333333333334.6657777777777825.469333333333335
292131.27617021276595833.06191489361701534.5376595744680925.337659574468084
292230.4086666666666732.1891111111111234.00133333333333523.963777777777775
292330.4283333333333332.1716666666666733.8579166666666724.296249999999997
├───────┴───────┴───────┴────────────────────┴────────────────────┴────────────────────┴────────────────────┤
24 rows 7 columns │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment