如何获取上周每天在线的用户?

How to get users which were online everyday last week?

数据示例:

id  visiting_time
1   13.01.2001 02:34
1   14.01.2001 02:36
1   15.01.2001 02:36
1   16.01.2001 02:37
1   17.01.2001 02:38
1   18.01.2001 02:39
1   19.01.2001 02:40
2   13.01.2001 02:35
2   15.01.2001 02:36
2   16.01.2001 02:37
2   17.01.2001 02:38
2   18.01.2001 02:39
2   19.01.2001 02:40

我想获取上周每天在线的所有用户,f.e。从 1 月 13 日 00:00 到 1 月 20 日 00:00。 对于我的数据样本,答案是:

id
1

以下代码仅在 visiting_time 列格式为 YYYY-MM-DD HH:MM 时有效,否则日期不可比较:

SELECT t.id FROM (SELECT id, COUNT(DISTINCT substr(visiting_time, 1, 10)) AS counter From table1 WHERE ((visiting_time >= '2001-01-13 00:00' AND visiting_time < '2001-01-20 00:00')) GROUP BY id) AS t WHERE t.counter=7

已考虑

everyday for the last week, f.e. from 13th january 00:00 till 20th january 00:00

I point it out myself. In general, I can choose any number of days I want.

我想它只能用作过滤器,所以任务是“在选定的时间间隔内每天在线查找用户

SELECT id,
       count(DISTINCT toDate(visiting_time)) AS number_of_days_visited
FROM user_visits
WHERE visiting_time BETWEEN '2001-01-13 00:00:00' AND '2001-01-20 00:00:00'
GROUP BY id
HAVING number_of_days_visited =
       round((toUInt32(toDateTime('2001-01-20 00:00:00')) - toUInt32(toDateTime('2001-01-13 00:00:00'))) / 60 / 60 / 24)

在 HAVING 中,我根据 WHERE 过滤器计算了天数。