See also Calendar Dimension
Very much of what we're interested in reporting on from a data warehouse is dependent on time. Time is critical for everything involving payment or receipt of money, for example. If £100 is paid into your account, you want to know when. Is it there now? Will it be paid tommorow? Next month? Next year? It makes a big difference. People talk about "temporal" and "non-temporal" databases, but most of the interesting data is "temporal".
Most data warehouses have a time dimension. This is usually at the level of a day - a specific date - or a specific time down to the nearest second. Of course we sometimes need different time intervals, such as weeks, months or milliseconds.
We already discussed the Calendar Dimension. Here we'll look at the time of day dimension. We could just use a
You might also wonder why we split the date and time in the dimensions, when SQL provides a
See the download page to get data and tools to build your time_of_day dimension. This is what you can do with the downloads:
The time_of_day.csv data file has times in the format hh:mm:ss from 00:00:00 to 23:59:59, with some basic attributes (day/night, am/pm).
The build_time_of_day.sql script:
If you need more columns you can adapt the Java source code and/or the scripts as you please. For example, in a car insurance company that installs a box to track the car, you might like to search for driving between 01:00am and 05:00am, because accidents are more likely to happen when driving at these times. You could add a risk factor to each time to make it easier to write such queries.