gpt4 book ai didi

php - Mysql查询上周非活跃用户

转载 作者:行者123 更新时间:2023-11-29 14:08:15 27 4
gpt4 key购买 nike

我有一个表action_info,每个用户都单击保存在其中。我需要获取上周不活动用户的计数。以下是 ACTIVE 用户的查询:

SELECT COUNT( DISTINCT user_id ) as active_for_week FROM action_info 
WHERE action_name = 'attack'
AND time >= (CURDATE( ) - INTERVAL 7 DAY)

最佳答案

这将从用户表中排除上周所有活跃的用户,因此只提供不活跃的用户。我希望这就是您正在寻找的内容。

SELECT COUNT(*) FROM users WHERE ID NOT IN(
SELECT DISTINCT user_id FROM action_info
WHERE action_name = 'attack'
AND time >= (CURDATE( ) - INTERVAL 7 DAY)
)

更新:

无需查询用户表,您可以执行以下操作:

SELECT COUNT(DISTINCT user_id) AS not_active_last_week FROM action_info 
WHERE action_name = 'attack' AND user_id NOT IN (
SELECT DISTINCT user_id FROM action_info
WHERE action_name = 'attack'
AND time >= (CURDATE( ) - INTERVAL 7 DAY)
)

它为您提供在某个时刻(但不是在上周)活跃的所有用户的数量。这是SQL fiddle

关于php - Mysql查询上周非活跃用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13989833/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com