在派生表上进行自定义计数

发布于 2025-01-25 04:21:37 字数 345 浏览 0 评论 0原文

我有一个事件表。上面的屏幕快照显示了事件表的派生结果。它基本上显示了用户在一周内发射的“ X”事件的总数。

我的业务逻辑说,如果用户在一周内发射超过5个活动,那么他在那一周是活跃的用户。如果用户在2周内活跃,那么他是忠实的用户。

我想在一周和忠实用户数量之间绘制图形(过去2周活跃的用户)。我被困在这张衍生的桌子上。请帮忙!

enter image description here

I have an events table. The above screenshot show a derived result from events table. It basically shows total number of 'x' event fired by a user in a week.

My business logic says, if a user fires more than 5 events in a week then he is an active user in that week. If a user is active in 2 weeks, then he is loyal user.

I want to plot a graph between week and number of loyal users (users who have been active in 2 weeks in past). I am stuck at this derive table. Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2025-02-01 04:21:37

我在这里要考虑的方法是:

,所以

SELECT Employee FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5

要让所有具有至少2个活跃周的员工就是这样

SELECT Employee, COUNT(*) as ActiveWeeks FROM (
SELECT Employee, datepart('year', Date), datepart('week', DATE) FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5) as activeWeeks
GROUP BY activeWeeks.Employee HAVING COUNT(*) >= 2

The approach I would consider here is:

So something like

SELECT Employee FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5

To then get all Employees having atleast 2 active weeks is like this

SELECT Employee, COUNT(*) as ActiveWeeks FROM (
SELECT Employee, datepart('year', Date), datepart('week', DATE) FROM Table GROUP BY Employee, datepart('year', Date), datepart('week', DATE) HAVING COUNT(*) >=5) as activeWeeks
GROUP BY activeWeeks.Employee HAVING COUNT(*) >= 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文