那么,像这样?那么,爬虫的 IP 地址会是 null 吗?
我想包含:
- 匿名用户
- 已登录用户
我想排除:
- 爬虫
- 工作人员用户
-- [参数]
-- string :date = '2020-01-01'
-- boolean :staff = false
WITH t AS (
SELECT date(:date) AS START
),
f AS (
SELECT id as user_id
FROM users u
WHERE u.moderator = 'True' or u.admin = 'True'
)
SELECT
user_id,
-- date_part('year', viewed_at) as year,
-- date_part('week', viewed_at) as week,
COUNT(topic_id) AS topics_viewed
FROM topic_views, t
WHERE viewed_at > t.START
AND ((ip_address is not null AND user_id is NULL) OR
user_id not in (select f.user_id from f))
GROUP BY user_id
ORDER BY topics_viewed DESC
-- GROUP BY year, week
-- ORDER BY year, week