开始使用免费开始使用

完成欺诈分析

到目前为止,您已经把日间水疗的数据拆分为进入与离开两类事件,并按时间顺序排序。该事件流包含两个关键字段:StartOrdinalStartOrEndOrdinalStartOrdinal 表示所有进入事件的时间顺序;StartOrEndOrdinal 表示所有进入与离开事件的时间顺序。有了这两项信息,您就可以找出同时在场访问的最大人数。

上一个练习的结果已存入名为 #StartStopOrder 的临时表中。

本练习是课程的一部分

SQL Server 中的时间序列分析

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

SELECT
	s.CustomerID,
	MAX(2 * s.StartOrdinal - s.StartOrEndOrdinal) AS MaxConcurrentCustomerVisits
FROM #StartStopOrder s
WHERE s.EntryCount = 1
GROUP BY s.CustomerID
-- The difference between 2 * start ordinal and the start/end
-- ordinal represents the number of concurrent visits
HAVING MAX(2 * s.___ - s.___) > 2
-- Sort by the largest number of max concurrent customer visits
ORDER BY ___ ___;
编辑并运行代码