Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. SELECT count(*) AS res,
  2. CASE
  3. WHEN EXISTS (select * from test_ip t WHERE t.ip = r.ip)
  4. OR (r.user_email ~ '(krzysztof.obstawski|aleksander.gregorek|norbert.gregorek|jakub.kowalczyk|jakub.jedynak|devices@intiaro.com|devices@agitive.com|devicesintiaro@gmail.com)')
  5. THEN true
  6. ELSE false
  7. END as test,
  8. r.event_date::date,
  9. (CASE
  10. WHEN application='Missing app data'
  11. THEN (select alias from clients c where c.client = r."domain")
  12. ELSE (select alias from clients c where c.client = r.application)
  13. END) as application,
  14. r.platform
  15. FROM combinedanalytics_19_02_2020_21_50 r
  16. WHERE
  17. ((r.cat='Product' AND r.act='Open')
  18. OR (r.cat='Product' AND r.lbl='Open')
  19. OR (r.act='Product' AND r.lbl='Open')
  20. OR (r.cat='Open' AND r.act='Product')
  21. OR (r.cat='Open' AND r.lbl='Product')
  22. OR (r.act='Open' AND r.lbl='Product'))
  23. GROUP BY
  24. CASE
  25. WHEN EXISTS (select * from test_ip t WHERE t.ip = r.ip)
  26. OR (r.user_email ~ '(krzysztof.obstawski|aleksander.gregorek|norbert.gregorek|jakub.kowalczyk|jakub.jedynak|devices@intiaro.com|devices@agitive.com|devicesintiaro@gmail.com)')
  27. THEN true
  28. ELSE false
  29. END,
  30. r.event_date::date, r.platform,
  31. CASE
  32. WHEN application='Missing app data'
  33. THEN (select alias from clients c where c.client = r."domain")
  34. ELSE (select alias from clients c where c.client = r.application)
  35. END;
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. create table if not exists tables_join(
  44. is_test boolean default false,
  45. date_business date,
  46. type text,
  47. client text,
  48. os text,
  49. session_id text,
  50. user_id int,
  51. data jsonb,
  52. ip text,
  53. app_version text);
  54.  
  55.  
  56. INSERT INTO tables_join(date_business, type, client, ip , session_id, user_id, app_version, data)
  57. SELECT (e.data->>'ts')::date, 'UnityWL', w.internalAppName, d.ip, d.session_uuid, d.user_id, d.app_version, e.data
  58. FROM analytics_event e
  59. inner join analytics_devicedata d on e."session_id" = d.id
  60. inner join whitelabel w on w.id = e.white_label_id;
  61.  
  62.  
  63. UPDATE tables_join
  64. SET is_test = test_ip.is_test
  65. FROM test_ip
  66. WHERE tables_join.ip = test_ip.ip;
  67.  
  68.  
  69.  
  70. UPDATE tables_join t
  71. SET os =
  72. CASE
  73. WHEN (t.client = 'EthanAllen' OR t.client='Ethan Allen')
  74. AND (t.app_version='1.8.3' OR t.app_version='1.8.8' OR t.app_version='1.8.10')
  75. AND t.date_business>'2019-02-13'
  76. THEN 'android'
  77. WHEN (t.client = 'EthanAllen' OR t.client='Ethan Allen')
  78. AND (t.app_version='1.8.4' OR t.app_version='1.8.7' OR t.app_version='1.8.9')
  79. AND t.date_business>'2019-02-14'
  80. THEN 'ios'
  81. ELSE u.platform
  82. END
  83. FROM user_userdevice u
  84. WHERE t.user_id = u.user_id;
  85.  
  86.  
  87. SELECT count(*) AS res, r.is_test, date_business, r.client, r.os
  88. FROM tables_join r
  89. WHERE
  90. ((r.data->>'cat'='Product' AND r.data->>'act'='Open')
  91. OR (r.data->>'cat'='Product' AND r.data->>'lbl'='Open')
  92. OR (r.data->>'act'='Product' AND r.data->>'lbl'='Open')
  93. OR (r.data->>'cat'='Open' AND r.data->>'act'='Product')
  94. OR (r.data->>'cat'='Open' AND r.data->>'lbl'='Product')
  95. OR (r.data->>'act'='Open' AND r.data->>'lbl'='Product'))
  96. GROUP BY r.is_test, date_business, r.os, r.client;
  97.  
  98. DROP table tables_join;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement