我有一个长形式的PHP函数来遍历所有用户并测试他们的活动状态。它很慢并且需要多个操作......这个SQL操作速度要快得多但是我的计数彼此不匹配。
我需要更新这个mySQL查询,以便通过1次添加和1次调整来完成它的工作。这样它就模仿了测试用户活动的确切行动/功能。
"SELECT DISTINCT last.user_id
FROM ss_usermeta as last
JOIN ss_usermeta as next on last.user_id = next.user_id
WHERE last.meta_key = 'last_trans_date' and last.meta_value <= CURDATE()
and next.meta_key = 'next_recurring_date' and next.meta_value + INTERVAL 9 day >= CURDATE()";
答案 0 :(得分:1)
你需要另外一个加入:
SELECT DISTINCT last.user_id
FROM ss_usermeta as last
JOIN ss_usermeta as next
on last.user_id = next.user_id
JOIN ss_usermeta as third
on third.user_id = next.user_id
WHERE last.meta_key = 'last_trans_date'
and last.meta_value <= CURDATE()
and next.meta_key = 'next_recurring_date'
and next.meta_value + INTERVAL 9 day >= CURDATE()
and third.meta_key = 'll_customer_id'
and third.meta_value is not null;