https://blog.stackademic.com/make-your-sql-query-smile-ctes-for-time-intervals-explained-6fc8797b3ef0