Guest User

Untitled

a guest
May 3rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. -- net new connector report
  2. select companies.name, companies.email, connectors.name, company_connectors.created_at from company_connectors
  3. join companies on company_connectors.company_id = companies.id
  4. join connectors on connectors.id = company_connectors.connector_id
  5. join summaries on summaries.company_id=company_connectors.company_id
  6. where
  7. company_connectors.created_at > CURRENT_DATE - INTERVAL '8 days'
  8. and company_connectors.synced = TRUE
  9. and email NOT LIKE '%@test.%' and email NOT LIKE '%avalara%'
  10. GROUP BY companies.name, companies.email, connectors.name, company_connectors.created_at;
  11.  
  12.  
  13. -- connector usage report
  14. -- ?? TBD - reduce to subscriptions purchased in period??
  15. select usage.company_name, usage.connector_name,
  16. count(subscriptions.id) as "subscriptions",
  17. sum(subscriptions.total_price) as "subscription total"
  18. FROM dblink('dbname=trustfilestorage user=deploy password=4BFkh59jDd9YCSu',
  19. 'SELECT account_id, company_name, connector_name, created_at from company_daily_usage
  20. where created_at > CURRENT_DATE - INTERVAL ''8 days''
  21. and usage = ''CONNECTOR_ACTIVE''
  22. ')
  23. AS usage(account_id INT, company_name TEXT, connector_name TEXT, usage_date TIMESTAMP)
  24. JOIN merchants on merchants.account_id = usage.account_id
  25. LEFT OUTER JOIN subscriptions on subscriptions.account_id = usage.account_id
  26. where email NOT LIKE '%test.%' and email NOT LIKE '%avalara%'
  27. and (subscriptions.expired_at ISNULL OR subscriptions.expired_at > now())
  28. and (subscriptions.revoked_at ISNULL and subscriptions.cancelled_at ISNULL )
  29. --and (subscriptions.created_at > CURRENT_DATE - INTERVAL '7 days' or subscriptions.id ISNULL )
  30.  
  31. GROUP BY usage.company_name, usage.connector_name
  32. ;
Advertisement
Add Comment
Please, Sign In to add comment