Roh*_*hit 3 database-design data-warehouse
如何最好地存储用户数据与日期/时间维度?Usecase是我试图每小时,每小时存储用户操作.如股票,喜欢,朋友等的数量.我有时间表和日期表.时间很容易 - 我每天的每一小时都有每行= user_id和colunms = 1到24.但问题是约会.如果我给每天= 1个colunm那么我每年将有365个colunms.我无法归档数据方式,因为分析也需要过去的数据.其他策略是什么?

dimDate : 1 row per date
dimTime : 1 row per minute
Run Code Online (Sandbox Code Playgroud)
在开始时,你必须说明事实表的" 颗粒 ",然后坚持下去.
如果谷物是一天,那么TimeKey总是指向"23:59"的关键.
如果谷物是一小时,则TimeKey指向"HH:59"的条目.
如果谷物是一分钟,那么TimeKey指向相应的"HH:MM"
如果谷物是15分钟,则TimeKey指向相应的"HH:14","HH:29","HH:44","HH:59"
等等...
-- How many new friends did specific user gain
-- in first three months of years 2008, 2009 and 2010
-- between hours 3 and 5 in the morning
-- by day of week
-- not counting holidays ?
select
DayOfWeek
, sum(NewFriends) as FriendCount
from factUserAction as f
join dbo.dimUser as u on u.UserKey = f.UserKey
join dbo.dimDate as d on d.DateKey = f.DateKey
join dbo.dimTime as t on t.TimeKey = f.TimeKey
where CalendarYear between 2008 and 2010
and MonthNumberInYear between 1 and 3
and t.Hour between 3 and 5
and d.IsHoliday = 'no'
and UserEmail = 'john_doe@gmail.com'
group by DayOfWeek
order by DayOfWeek ;
Run Code Online (Sandbox Code Playgroud)