ahmedrahil786

Installs by Month_ Rahil

May 26th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. set @start := '2018-12-31 00:00';
  2. set @start2 := '2019-11-1 00:00';
  3.  
  4. select
  5. month(d.created_at + interval '8' hour) as month,
  6. count(distinct case when d.state = 'active' then d.uuid end) as Active_installs_2019,
  7. count(distinct case when d.state = 'badToken' then d.uuid end) as badToken_installs_2019,
  8. count(distinct case when d.state = 'duplicate' then d.uuid end) as duplicate_installs_2019,
  9. count(distinct case when d.state = 'logout' then d.uuid end) as logout_installs_2019
  10.  
  11. from devices d
  12. where d.created_at + interval '8' hour >= @start
  13. and d.created_at + interval '8' hour <= @start2
  14. group by 1 ;
  15.  
  16. set @start3 := '2017-12-31 00:00';
  17. set @start4 := '2019-1-1 00:00';
  18.  
  19. select
  20. month(d.created_at + interval '8' hour) as month,
  21. count(distinct case when d.state = 'active' then d.uuid end) as Active_installs_2018,
  22. count(distinct case when d.state = 'badToken' then d.uuid end) as badToken_installs_2018,
  23. count(distinct case when d.state = 'duplicate' then d.uuid end) as duplicate_installs_2018,
  24. count(distinct case when d.state = 'logout' then d.uuid end) as logout_installs_2018
  25. from devices d
  26. where d.created_at + interval '8' hour >= @start3
  27. and d.created_at + interval '8' hour <= @start4
  28. group by 1 ;
Advertisement
Add Comment
Please, Sign In to add comment