Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1.  
  2. -- who purchased from the paywall
  3. select companies.name, companies.email, date_trunc('Month', companies."createdAt") as "signedup_at",
  4. summaries.filed_return_count, summaries.gross_tax_collected, summaries.gross_sales,
  5. summaries.file_count, summaries.connector_count, summaries.item_count, summaries.pastdue_return_count,
  6. summaries.bank_accounts
  7. from companies
  8. join summaries ON summaries.company_id = companies.id
  9. where
  10. companies.account_id in (
  11. SELECT account_licenses.account_id
  12. FROM account_licenses
  13. WHERE account_licenses.created_at > '05/01/2016'
  14. and account_licenses.trial = false
  15. and (account_licenses.license_id = 47 or account_licenses.license_id = 1)
  16. --AND account_licenses.trial = FALSE
  17. );
  18.  
  19.  
  20. -- users who didn't buy - need all sessions
  21. select companies.name, companies.email, date_trunc('Month', companies."createdAt") as "signedup_at",
  22. summaries.filed_return_count, summaries.gross_tax_collected, summaries.gross_sales,
  23. summaries.file_count, summaries.connector_count, summaries.item_count, summaries.pastdue_return_count,
  24. summaries.bank_accounts
  25. from companies
  26. join summaries ON summaries.company_id = companies.id
  27. join users on users.account_id = companies.account_id
  28. where
  29. companies.email NOT LIKE '%@test.%' AND companies.email NOT LIKE '%avalara%'
  30. and users.account_id NOT IN -- valid subscriptions
  31. (
  32. SELECT DISTINCT account_licenses.account_id
  33. FROM account_licenses
  34. WHERE
  35. account_licenses.revoke = FALSE
  36. AND
  37. (account_licenses.expiration_date ISNULL or account_licenses.expiration_date > now() )
  38. )
  39. and companies.id in ( -- all recent sessions
  40. select STORAGE.target_company_id FROM dblink('dbname=trustfilestorage user=deploy password=4BFkh59jDd9YCSu', 'SELECT target_company_id
  41. FROM audit_logs
  42. where
  43. created_at > ''05/01/2016''
  44. and target_company_id = source_company_id')
  45. AS STORAGE ( target_company_id INT)
  46. JOIN merchants ON merchants.id = STORAGE.target_company_id
  47. WHERE merchants.email NOT LIKE '%@test.%' AND merchants.email NOT LIKE '%avalara%'
  48. );
  49.  
  50.  
  51.  
  52. -- paywall funnel - need better "who viewed the paywall" numbers
  53.  
  54. select "date",
  55. sum("sessions") as "viewed paywall",
  56. sum("subscribe") as "clicked subscribe",
  57. sum("purchase") as "purchased"
  58.  
  59. from
  60. (
  61. (SELECT
  62. date_trunc('Day', storage.created_at) AS "date",
  63. count(storage.target_company_id) AS "sessions",
  64. 0 AS "subscribe",
  65. 0 AS "purchase"
  66. FROM dblink('dbname=trustfilestorage user=deploy password=4BFkh59jDd9YCSu','SELECT created_at, target_company_id
  67. FROM audit_logs
  68. where
  69. created_at > now() - INTERVAL ''7 days''
  70. and target_company_id = source_company_id')
  71. AS storage(created_at TIMESTAMP, target_company_id INT)
  72. JOIN merchants on merchants.id = storage.target_company_id
  73. where merchants.email NOT LIKE '%@test.%' AND merchants.email NOT LIKE '%avalara%'
  74. GROUP BY 1
  75. ORDER BY 1)
  76.  
  77. UNION
  78.  
  79. (SELECT
  80. date_trunc('Day', subscriptions.created_at) AS "date",
  81. 0 AS "sessions",
  82. count(subscriptions.id) AS "subscribe",
  83. 0 AS "purchase"
  84. FROM subscriptions
  85. JOIN companies ON companies.account_id = subscriptions.account_id
  86. WHERE
  87. companies.email NOT LIKE '%@test.%' AND companies.email NOT LIKE '%avalara%'
  88. AND subscriptions.created_at > now() - INTERVAL '7 days'
  89. GROUP BY 1
  90. ORDER BY 1)
  91.  
  92. UNION
  93.  
  94. (SELECT
  95. date_trunc('Day', subscriptions.created_at) AS "date",
  96. 0 AS "sessions",
  97. 0 AS "subscribe",
  98. count(subscriptions.id) AS "purchase"
  99. FROM subscriptions
  100. JOIN companies ON companies.account_id = subscriptions.account_id
  101. WHERE
  102. companies.email NOT LIKE '%@test.%' AND companies.email NOT LIKE '%avalara%'
  103. AND subscriptions.created_at > now() - INTERVAL '7 days'
  104. GROUP BY 1
  105. ORDER BY 1
  106. )
  107.  
  108. ) a
  109. GROUP BY "date"
  110. ORDER BY "date";
  111.  
  112.  
  113.  
  114. -- users that logged but didn't buy
  115. SELECT
  116. date_trunc('Day', storage.created_at) as "Day",
  117. merchants.name
  118. FROM dblink('dbname=trustfilestorage user=deploy password=4BFkh59jDd9YCSu','SELECT created_at, target_company_id
  119. FROM audit_logs
  120. where
  121. created_at > now() - INTERVAL ''7 days''
  122. and target_company_id = source_company_id')
  123. AS storage(created_at TIMESTAMP, target_company_id INT)
  124. JOIN merchants on merchants.id = storage.target_company_id
  125. where merchants.email NOT LIKE '%@test.%' AND merchants.email NOT LIKE '%avalara%'
  126. GROUP BY storage.created_at, merchants.name
  127.  
  128.  
  129. select * from subscriptions where created_at > '05/01/2016'
  130.  
  131. select account_id from companies where name = '05-02@test.co'; --8323
  132. select * from account_licenses where account_id = 8323;
  133.  
  134.  
  135. select account_id from companies where name = 'First Botany';
  136. select * from account_licenses where account_id = 2268;
  137. select * from subscriptions where account_id = 2268;
  138.  
  139.  
  140. select id, account_id from companies where name = '05-02@test.co';
  141. select * from account_licenses where account_id = 8323;
  142. select * from subscriptions where account_id = 8323;
  143. select * from summaries where company_id = 9198;
  144.  
  145.  
  146. -- people that viewed the paywall. unlicensed access
  147. SELECT
  148. date_trunc('Day', storage.created_at) AS "date",
  149. count(storage.target_company_id) AS "sessions",
  150. 0 AS "subscribe",
  151. 0 AS "purchase"
  152. FROM dblink('dbname=trustfilestorage user=deploy password=4BFkh59jDd9YCSu','SELECT created_at, target_company_id
  153. FROM audit_logs
  154. where
  155. created_at > now() - INTERVAL ''7 days''
  156. and target_company_id = source_company_id')
  157. AS storage(created_at TIMESTAMP, target_company_id INT)
  158. JOIN merchants on merchants.id = storage.target_company_id
  159.  
  160. where merchants.email NOT LIKE '%@test.%' AND merchants.email NOT LIKE '%avalara%'
  161. GROUP BY 1
  162. ORDER BY 1
  163.  
  164.  
  165. SELECT
  166. date_trunc('Day', storage.created_at) AS "date",
  167. merchants.id AS "id",
  168. account_licenses.id,
  169. account_licenses.trial,
  170. account_licenses.expiration_date,
  171. account_licenses.license_id
  172.  
  173. FROM dblink('dbname=trustfilestorage user=deploy password=4BFkh59jDd9YCSu','SELECT created_at, target_company_id
  174. FROM audit_logs
  175. where
  176. created_at > now() - INTERVAL ''7 days''
  177. and target_company_id = source_company_id')
  178. AS storage(created_at TIMESTAMP, target_company_id INT)
  179. JOIN merchants on merchants.id = storage.target_company_id
  180. LEFT OUTER JOIN account_licenses on account_licenses.account_id = merchants.account_id
  181. where merchants.email NOT LIKE '%@test.%' AND merchants.email NOT LIKE '%avalara%'
  182.  
  183.  
  184. select * from licenses;
  185.  
  186.  
  187. select id, account_id from companies where name = 'foru International Corporation'; --6879 7070
  188. select * from summaries where company_id = 6879;
  189. select * from subscriptions where account_id = 2268;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement