ProCom
Well-known member
I have a handful of threads here on xf asking about SQL queries. Well, in my quest to make the ultimate SQL query to gather data about my members (especially the "best" new members) I built this monstrosity out of cobbled-together queries.
Basically the idea is this: We all have our "Members" tab that shows data on members from "all time"... but I've found that a lot of amazing new members (especially on really old / active forums) can get overshadowed.
So, this query helps me to identify who the "best" new members are. Lots of variables can be tweaked to your liking:
(that last bit adds some limits to the query so I only pull the "best" new members over the past 185 days. Feel free to strip it out completely for non-limited data.
I'm no expert at this stuff, so if you have any suggestions / fixes, let me know!
Basically the idea is this: We all have our "Members" tab that shows data on members from "all time"... but I've found that a lot of amazing new members (especially on really old / active forums) can get overshadowed.
So, this query helps me to identify who the "best" new members are. Lots of variables can be tweaked to your liking:
Code:
SELECT
user.user_id
,user.username
,from_unixtime(user.register_date, '%m/%d/%Y') as Registered
,from_unixtime(user.last_activity, '%m/%d/%Y') as Last_Active
,user.message_count
,user.like_count,user.trophy_points
,ifnull(pc.post_count, 0) as recent_posts
,ifnull(lc.like_count, 0) as recent_likes
,ROUND(user.like_count * 100.0 / user.message_count, 1) AS all_time_like_ratio
,ROUND(lc.like_count * 100.0 / pc.post_count, 1) AS recent_like_ratio
,CONCAT('https://www.youURL.com/members/',user.user_id) AS Link
FROM xf_user user
left join (
select count(*) as post_count, p.*
from xf_post as p
where post_date > unix_timestamp(date_add(now(), interval -90 day))
group by p.user_id
) as pc on (pc.user_id = user.user_id)
left join (
select count(like_id) as like_count, l.*
from xf_liked_content l
where like_date > unix_timestamp(date_add(now(), interval -90 day))
group by content_user_id
) as lc on (lc.content_user_id = user.user_id)
WHERE user.message_count > 100 and lc.like_count > 10 and user.register_date > unix_timestamp(date_add(now(), interval -185 day))
order by recent_like_ratio desc
(that last bit adds some limits to the query so I only pull the "best" new members over the past 185 days. Feel free to strip it out completely for non-limited data.
I'm no expert at this stuff, so if you have any suggestions / fixes, let me know!