林拼圖至於如何建立我的事實和尺寸procude以下結果:MDX查詢隨着時間間隔計數登錄OCCURENCES
我想指望人們記錄每個時間間隔的出現次數的數量。
在這種情況下每隔30分鐘。它看起來像這樣
Example: Person1 login at 10:05:00 and logout at 12:10:00
Person2 login at 10:45:00 and logout at 11:25:00
Person3 login at 11:05:00 and logout at 14:01:00
TimeStart TimeEnd People logged
00:00:00 00:30:00 0
00:30:00 01:00:00 0
...
10:00:00 10:30:00 1
10:30:00 11:00:00 2
11:00:00 11:30:00 3
11:30:00 12:00:00 2
12:00:00 12:30:00 2
12:30:00 13:00:00 1
13:00:00 13:30:00 1
13:30:00 14:00:00 1
14:00:00 14:30:00 0
...
23:30:00 00:00:00 0
所以我必須包含小時,halfhour一個DimTime和DimDate表,quarterhour 和我有具有以下一個FactTimestamp表:
DateLoginID that points to DimDate dateID
DateLogoutID that points to DimDate dateID
TimeLoginID that points to DimTime timeID
TimeLogoutID that points to DimTime timeID
我想知道我需要達到什麼樣的立方體設計?
香港專業教育學院做了在SQL中,如果能夠幫助:
--Create tmp table for time interval
CREATE TABLE #tmp(
StartRange time(0),
EndRange time(0),
);
--Interval set to 30 minutes
DECLARE @Interval int = 30
-- Example with @Date = 2017-07-27: Set starttime at 2017-07-27 00:00:00
DECLARE @StartTime datetime = DATEADD(HOUR,0, @Date)
--Set endtime at 2017-07-27 23:59:59
DECLARE @EndTime datetime = DATEADD(SECOND,59,DATEADD(MINUTE,59,DATEADD(HOUR,23, @Date)))
--Populate tmp table with the time interval. from midnight to 23:59:59
;WITH cSequence AS
(
SELECT
@StartTime AS StartRange,
DATEADD(MINUTE, @Interval, @StartTime) AS EndRange
UNION ALL
SELECT
EndRange,
DATEADD(MINUTE, @Interval, EndRange)
FROM cSequence
WHERE DATEADD(MINUTE, @Interval, EndRange) <= @EndTime
)
INSERT INTO #tmp SELECT cast(StartRange as time(0)),cast(EndRange as time(0)) FROM cSequence OPTION (MAXRECURSION 0);
--Insert last record 23:30:00 to 23:59:59
INSERT INTO #tmp (StartRange, EndRange) values ('23:30:00','23:59:59');
SELECT tmp.StartRange as [Interval], COUNT(ts.TimeIn) as [Operators]
FROM #tmp tmp
JOIN Timestamp ts ON
--If timeIn is earlier than StartRange OR within the start/end range
(CAST(ts.TimeIn as time(0)) <= tmp.StartRange OR CAST(ts.TimeIn as time(0)) BETWEEN tmp.StartRange AND tmp.EndRange)
AND
--AND If timeOut is later than EndRange OR within the start/end range
CAST(ts.[TimeOut] as time(0)) >= tmp.EndRange OR CAST(ts.[TimeOut] as time(0)) BETWEEN tmp.StartRange AND tmp.EndRange
GROUP BY tmp.StartRange, tmp.EndRange
END
真的任何暗示對如何實現它在MDX將不勝感激。
很有意思。我不知道這個定期的快照表解決方案。我會仔細看看這個。謝謝! –
通過Kimball閱讀,他詳細解釋了何時何時不使用它以及如何使用它。 – nsousa
如果我必須在MDX中完成這項工作,我需要在我的設計上進行更改才能使其成爲可能? @nsousa –