Advertisement
krasimirvelichkov

Untitled

Jul 19th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. | 359338047 | ieltsadv | localhost | my_ieltsadvantage | Query | 1 | Sending data | SELECT
  2. u.ID AS user_id,
  3.  
  4. (
  5. SELECT t.id
  6. FROM wp_mepr_transactions AS t
  7. WHERE t.user_id = u.ID
  8. AND t.status = 'complete'
  9. ORDER BY t.created_at ASC
  10. LIMIT 1
  11. ) AS first_txn_id,
  12. (
  13. SELECT t.id
  14. FROM wp_mepr_transactions AS t
  15. WHERE t.user_id = u.ID
  16. AND t.status = 'complete'
  17. ORDER BY t.created_at DESC
  18. LIMIT 1
  19. ) AS latest_txn_id,
  20. (
  21. SELECT COUNT(*)
  22. FROM wp_mepr_transactions AS t
  23. WHERE t.user_id=u.ID
  24. AND t.txn_type IN ('payment', 'sub_account')
  25. ) AS txn_count,
  26. (
  27. SELECT COUNT(*)
  28. FROM wp_mepr_transactions AS t
  29. WHERE t.user_id = u.ID
  30. AND t.status = 'complete'
  31. AND t.txn_type IN ('payment', 'sub_account')
  32. AND ( (
  33. t.expires_at IS NOT NULL
  34. AND t.expires_at <> '0000-00-00 00:00:00'
  35. AND t.expires_at < '2019-07-19 10:52:46'
  36. )
  37. )
  38. ) AS expired_txn_count,
  39. (
  40. SELECT COUNT(*)
  41. FROM wp_mepr_transactions AS t
  42. WHERE t.user_id=u.ID
  43. AND t.status = 'complete'
  44. AND t.txn_type IN ('payment', 'sub_account')
  45. AND (
  46. t.expires_at IS NULL
  47. OR t.expires_at = '0000-00-00 00:00:00'
  48. OR t.expires_at > '2019-07-19 10:52:46'
  49. )
  50. ) AS active_txn_count,
  51. (
  52. SELECT COUNT(*)
  53. FROM wp_mepr_transactions AS t
  54. JOIN wp_mepr_subscriptions AS sub
  55. ON t.subscription_id = sub.id
  56. WHERE t.user_id=u.ID
  57. AND t.txn_type = 'subscription_confirmation'
  58. AND (
  59. t.expires_at IS NULL
  60. OR t.expires_at = '0000-00-00 00:00:00'
  61. OR t.expires_at > '2019-07-19 10:52:46'
  62. )
  63. AND sub.trial IS TRUE
  64. AND sub.trial_amount = 0.00
  65. ) AS trial_txn_count,
  66. (
  67. SELECT COUNT(*)
  68. FROM wp_mepr_subscriptions AS s
  69. WHERE s.user_id=u.ID
  70.  
  71. ) AS sub_count,
  72. (
  73. SELECT COUNT(*)
  74. FROM wp_mepr_subscriptions AS s
  75. WHERE s.user_id=u.ID
  76. AND s.status='pending'
  77. ) AS pending_sub_count,
  78. (
  79. SELECT COUNT(*)
  80. FROM wp_mepr_subscriptions AS s
  81. WHERE s.user_id=u.ID
  82. AND s.status='active'
  83. ) AS active_sub_count,
  84. (
  85. SELECT COUNT(*)
  86. FROM wp_mepr_subscriptions AS s
  87. WHERE s.user_id=u.ID
  88. AND s.status='suspended'
  89. ) AS suspended_sub_count,
  90. (
  91. SELECT COUNT(*)
  92. FROM wp_mepr_subscriptions AS s
  93. WHERE s.user_id=u.ID
  94. AND s.status='cancelled'
  95. ) AS cancelled_sub_count,
  96. (
  97. SELECT GROUP_CONCAT(
  98. DISTINCT t.product_id
  99. ORDER BY t.product_id
  100. SEPARATOR ','
  101. )
  102. FROM wp_mepr_transactions AS t
  103. WHERE t.user_id = u.ID
  104. AND (
  105. t.expires_at > '2019-07-19 10:52:46'
  106. OR t.expires_at = '0000-00-00 00:00:00'
  107. OR t.expires_at IS NULL
  108. )
  109. AND ( (
  110. t.txn_type IN ('payment','sub_account','fallback')
  111. AND t.status='complete'
  112. ) OR (
  113. t.txn_type='subscription_confirmation'
  114. AND t.status='confirmed'
  115. )
  116. )
  117. ) AS memberships,
  118. (
  119. SELECT e.id
  120. FROM wp_mepr_events AS e
  121. WHERE e.evt_id=u.ID
  122. AND e.evt_id_type='users'
  123. AND e.event='login'
  124. ORDER BY e.created_at DESC
  125. LIMIT 1
  126. ) AS last_login_id,
  127. (
  128. SELECT COUNT(*)
  129. FROM wp_mepr_events AS e
  130. WHERE e.evt_id=u.ID
  131. AND e.evt_id_type='users'
  132. AND e.event='login'
  133. ) AS login_count,
  134. (
  135. SELECT sum(t.total)
  136. FROM wp_mepr_transactions AS t
  137. WHERE t.user_id=u.ID
  138. AND t.status IN ('complete','confirmed')
  139. ) AS total_spent,
  140. '2019-07-19 10:52:46' AS updated_at
  141. FROM wp_users AS u
  142.  
  143. WHERE u.ID = 272611
  144.  
  145.  
  146. LIMIT 1 | 0.000 |
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement