Advertisement
festinko

Untitled

Dec 16th, 2022
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.62 KB | None | 0 0
  1.  
  2.  
  3. WITH
  4.  
  5. usersFirstAddonPayment as (
  6.  
  7. /*First users payment for add on*/
  8. SELECT
  9.     userID,
  10.     MIN(DATE(paymentDateTime)) firstSubuserPaymentDate
  11. FROM
  12.     payments
  13.  
  14. WHERE
  15.  
  16.   paymentType = 3
  17.     AND productID = 2
  18.     AND paymentDateTime > '2022-12-11'
  19.  
  20. GROUP BY
  21.     userID
  22.  
  23. ORDER BY
  24.   firstSubuserPaymentDate DESC),
  25.  
  26. firstAddonPayment as (
  27.     /*Count of users with first payment for sub user by date*/
  28.     SELECT
  29.         firstSubuserPaymentDate,
  30.         count(userID)
  31.    
  32.     FROM
  33.         usersFirstAddonPayment
  34.    
  35.     GROUP BY
  36.         firstSubuserPaymentDate
  37.    
  38.     ORDER BY
  39.         firstSubuserPaymentDate DESC)
  40.        
  41. SELECT
  42. *
  43. FROM
  44. firstAddonPayment
  45.  
  46.  
  47.  
  48.        
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement