Advertisement
festinko

Untitled

Oct 12th, 2022
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.44 KB | None | 0 0
  1. WITH
  2. /*list of users with last subs payment via PayPal*/
  3.  
  4. lastPayPalPayment as (
  5.   SELECT
  6.     p.userID
  7.  
  8.   FROM
  9.     `uptimerobot-001.ur.payments` p
  10.   LEFT JOIN
  11.     (SELECT
  12.       userID,
  13.       MAX(paymentDateTime) lastPaymentDateTime
  14.     FROM
  15.       `uptimerobot-001.ur.payments`
  16.     WHERE
  17.       paymentProcessor = 2
  18.             AND paymentType = 2
  19.     GROUP BY
  20.       userID
  21.     ) as lp
  22.  
  23.   ON lp.userID = p.userID AND p.paymentDateTime = lastPaymentDateTime
  24.  
  25. WHERE
  26.     lp.userID IS NOT NULL
  27.  
  28. ),
  29.  
  30. preparedData as (
  31.  
  32. /*Users with payment for SMS / call notification credits & not active SMS / call alert contact*/
  33. SELECT
  34.     p.userID
  35.  
  36. FROM
  37.     `uptimerobot-001.ur.payments` p
  38.  
  39. LEFT JOIN
  40.     `uptimerobot-001.ur.users` u
  41.  
  42.     ON p.userID = u.userID
  43.  
  44. WHERE
  45. paymentPeriod = 0
  46. AND (userSMSRefill = 0  OR userSMSRefill IS NULL)
  47. AND u.userID IS NOT NULL
  48. AND p.userID NOT IN (
  49.  
  50. /*Users with active SMS / Voice call alert contact*/
  51.        
  52.     SELECT
  53.         userID
  54.     FROM
  55.         `uptimerobot-001.ur.alertcontacts`
  56.                    
  57.     WHERE
  58.         alertContactType IN (8,14)
  59.         AND alertContactStatus = 2
  60.                    
  61.     GROUP BY
  62.     userID
  63. )
  64.  
  65. /*filtering only customers with last subs payment via PayPal*/
  66. AND p.userID IN (
  67. SELECT
  68.     userID
  69. FROM
  70.     lastPayPalPayment
  71. )
  72.  
  73. GROUP BY
  74.     p.userID)
  75.  
  76.  
  77.  SELECT
  78.     userID,
  79.     userEmail,
  80.     userNewsletter,
  81.     userSMSRefill
  82.  
  83. FROM
  84.   `uptimerobot-001.ur.users` u
  85.  
  86. WHERE
  87.   userID IN (
  88.     SELECT
  89.       userID
  90.     FROM
  91.       preparedData
  92.   )
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement