Advertisement
festinko

Untitled

Oct 13th, 2022
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.01 KB | None | 0 0
  1. WITH
  2.  
  3. /*New Customers for selected date range*/
  4.  newCustomers as (
  5.    SELECT
  6.     userID,
  7.     RAND() random
  8.    FROM
  9.     `uptimerobot-001.ur.payments`
  10.   WHERE
  11.     paymentPeriod IN (1,12)
  12.     AND paymentStatus = 1
  13.     AND paymentNewUpgradeRenewal = 1
  14.    
  15.     /*Set the date range for desired reporting period*/
  16.     AND paymentDateTime BETWEEN "2022-01-01 00:00:01" AND "2022-01-31 23:59:59"
  17.  
  18.   ORDER BY
  19.     random
  20.  ),
  21.  
  22. /*New users for selected date range with YT as reported source of acguisition*/
  23.  reportedSourceOfAcquisition as (
  24.    SELECT
  25.     userID,
  26.     userRegisterDateTime,
  27.     userReportedOrigin,
  28.     RAND() random
  29.   FROM
  30.     `uptimerobot-001.ur.users`
  31.  
  32.   WHERE
  33.     /*Set the date range for desired reporting period*/
  34.     userRegisterDateTime BETWEEN "2022-01-01 00:00:01" AND "2022-01-31 23:59:59"
  35.     AND userReportedOrigin = "youtube"
  36.   ORDER BY
  37.     random
  38.  )
  39.  
  40. SELECT
  41.   *
  42.  
  43. FROM
  44.   reportedSourceOfAcquisition
  45.  
  46. WHERE
  47.   userID NOT IN (SELECT userID FROM newCustomers)
  48.  
  49. limit 500
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement