Query for getting new memberships only

9 years 2 months ago #258451 by hac
Hi,

My client needs a report to show only new memberships between a certain period. I have been able to figure out how to get all memberships during the period, but I don't know how to pare that down to only show the memberships that are new and not renewals.

Here is my query for all memberships during a period:
SELECT cb.lastname, cb.firstname, cbp.name, cbs.status, cbs.expiry_date, u.email, cbs . *
FROM zH2b_comprofiler AS cb
LEFT JOIN zH2b_users AS u ON u.id = cb.user_id
LEFT JOIN zH2b_cbsubs_subscriptions AS cbs ON cbs.user_id = cb.user_id
LEFT JOIN zH2b_cbsubs_plans AS cbp ON cbs.plan_id = cbp.id
LEFT JOIN zH2b_user_usergroup_map AS ugm ON cb.user_id = ugm.user_id
WHERE u.block !=1
AND cb.approved =1
AND cb.banned =0
AND ugm.group_id =2
AND cbs.status = 'A'
AND cbs.plan_id >0
AND cbs.subscription_date > '2015-01-01 10:15:04'
AND cbs.subscription_date < '2015-02-01 10:15:04'
ORDER BY cbs.subscription_date DESC , cb.lastname ASC , `cb`.`firstname` ASC

What do I need to add to the query to get only new memberships?

I looked at the previous status field but didn't know what the codes mean, they were all R or I but the I ones had both new and renewals, same with the R.

Thank you.

Please Log in to join the conversation.

9 years 2 months ago #258489 by krileon
Replied by krileon on topic Query for getting new memberships only
The previous_status column will be I for initialized and the status column will be A for active for all new first time purchases. If the previous_status is R and status is A then it's a renewal. You can also check for the previous_expiry_date to be NULL, which is an indication of a new subscription as well.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.154 seconds

Facebook Twitter LinkedIn