Advertisement
theitd

MySQL Subscriber Queries

Jul 9th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.15 KB | None | 0 0
  1. /** Current Subscribers **/
  2. SELECT COUNT(sub.user_id) as current_subscribers, plan.title
  3. FROM `xiszt_payplans_subscription` sub
  4. LEFT JOIN `xiszt_payplans_plan` plan ON plan.plan_id = sub.plan_id
  5. WHERE sub.status = 1601
  6. GROUP BY sub.plan_id;
  7.  
  8. /** Expired Subscribers **/
  9. SELECT COUNT(sub.user_id) as expired_subscribers, plan.title
  10. FROM `xiszt_payplans_subscription` sub
  11. LEFT JOIN `xiszt_payplans_plan` plan ON plan.plan_id = sub.plan_id
  12. WHERE sub.status = 1603
  13. AND sub.user_id NOT IN (SELECT s.user_id FROM `xiszt_payplans_subscription` s WHERE s.status = 1601)
  14. GROUP BY sub.plan_id;
  15.  
  16. /** Renewals by COUNT(user_id) **/
  17. SELECT COUNT(sub.user_id) as renewals, plan.title
  18. FROM `xiszt_payplans_subscription` sub
  19. LEFT JOIN `xiszt_payplans_plan` plan ON plan.plan_id = sub.plan_id
  20. WHERE sub.expiration_date > DATE_ADD(sub.subscription_date, INTERVAL 1 YEAR)
  21. AND sub.expiration_date > NOW()
  22. GROUP BY sub.plan_id;
  23.  
  24. /** User Count **/
  25. SELECT COUNT(id) as user_count
  26. FROM `xiszt_users`;
  27.  
  28. /** Uploaded Files **/
  29. SELECT COUNT(id) as file_count FROM `xiszt_jbackend_logs_uploads`;
  30.  
  31. /* Subscribers ACTIVE */
  32. SELECT sub.user_id FROM xiszt_payplans_subscription sub
  33. WHERE sub.status = '1601'
  34. AND (plan_id = 10 OR plan_id = 2)
  35. AND sub.user_id != '102'
  36. GROUP BY user_id;
  37.  
  38. /* Subscribers EXPIRED */
  39. SELECT sub.user_id FROM xiszt_payplans_subscription sub
  40. WHERE sub.status = '1603'
  41. AND (plan_id = 10 OR plan_id = 2)
  42. AND sub.user_id NOT IN (SELECT s.user_id FROM xiszt_payplans_subscription s WHERE status = '1601' AND (s.plan_id = 10 OR s.plan_id = 2) GROUP BY s.user_id)
  43. AND sub.user_id != '102'
  44. GROUP BY sub.user_id;
  45.  
  46. /* Subscribers ALL */
  47. SELECT sub.user_id FROM xiszt_payplans_subscription sub
  48. WHERE (plan_id = 10 OR plan_id = 2)
  49. AND (sub.status = '1601' OR sub.status = '1603')
  50. AND sub.user_id != '102'
  51. GROUP BY sub.user_id;
  52.  
  53.  
  54. /* Contributors ALL */
  55. SELECT up.userid FROM xiszt_jbackend_logs_uploads up
  56. WHERE up.time >= NOW()-INTERVAL 4 MONTH
  57. GROUP BY up.userid
  58. ORDER BY up.userid;
  59.  
  60. /* Users (ALL) */
  61. SELECT ju.id
  62. FROM xiszt_users ju
  63. LEFT JOIN xiszt_user_usergroup_map g ON ju.id = g.user_id
  64. WHERE g.group_id != '8'
  65. AND ju.id != '102'
  66. GROUP BY ju.id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement