I came across a data warehousing practice question. I tried to think of various ways to design this but I'm not sure what the best practices are. The question deals with designing a data warehouse for a parking lot and writing a SQL query for getting the parking fees.
The constraints are as follows:
Weekday hourly rates
Two wheeler - 1$
Four wheeler - 2$
Weekend hourly rates
Two wheeler - 2$
Four wheeler - 3$
A car is parked from Friday morning 9am till Saturday 10am. Design a data warehouse to stored this data and write a SQL to get the parking fees for a vehicle.
I could only think of below two ways of representing it,
- Approach 1
Having a date_id, time_id and a type. Querying the parking fees can be difficult here since we do not have data at the grain of an hour. Difficult to calculate parking fees but consume less data
fact_parking_lot_data
fact_key | vehicle_id | date_id | time_id | type |
---|---|---|---|---|
1 | 1 | 20220506 | 9 | in |
2 | 1 | 20220507 | 22 | out |
- Approach 2
Having a date_id, time_id for each hour of the day. This would created multiple fact table entries for the vehicle, if the vehicle is parked for 2 days then it would have 48 records. Easy to calculate parking fees but consume lot of storage
fact_parking_lot_data
fact_key | vehicle_id | date_id | time_id |
---|---|---|---|
1 | 1 | 20220506 | 9 |
2 | 1 | 20220506 | 10 |
3 | 1 | 20220506 | 11 |
4 | 1 | 20220506 | 12 |
. | . | . | . |
. | . | . | . |
. | . | . | . |
26 | 1 | 20220507 | 10 |
Any thoughts or suggestion would be really appreciated. Thank you !