Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. -- raw sql results do not include filled-in values for 'employers_test.install_time_group_week'
  2.  
  3.  
  4. SELECT
  5. DATE_FORMAT(DATE_TRUNC('DAY', DATE_ADD('day', (0 - MOD((DAY_OF_WEEK((cast(employers_test.install_time as timestamp) AT TIME ZONE 'Europe/Luxembourg')) % 7) - 1 + 7, 7)), (cast(employers_test.install_time as timestamp) AT TIME ZONE 'Europe/Luxembourg'))), '%Y-%m-%d') AS "employers_test.install_time_group_week",
  6. -- COALESCE(
  7. -- COALESCE(
  8. -- (
  9. SUM(DISTINCT
  10. CAST(
  11. FLOOR(
  12. COALESCE(employers_test.appsflyer_installs ,0)*(1000000*1.0)
  13. )
  14. AS DECIMAL(38,0)
  15. )
  16. ) AS "foo"
  17. ,
  18. SUM(DISTINCT
  19. (
  20. CAST(
  21. FLOOR(
  22. COALESCE(employers_test.appsflyer_installs ,0)*(1000000*1.0)
  23. )
  24. AS DECIMAL(38,0)
  25. )
  26. )
  27. +
  28. (
  29. CAST(
  30. FROM_BASE(
  31. SUBSTR(
  32. TO_HEX(
  33. MD5(
  34. CAST(
  35. CAST(employers_test.user_id AS VARCHAR)
  36. AS VARBINARY
  37. )
  38. )
  39. )
  40. ,1,14
  41. )
  42. ,16
  43. )
  44. AS DECIMAL(38, 0)
  45. )
  46. *
  47. CAST(10000000000 AS DECIMAL(38, 0))
  48. +
  49. CAST(
  50. FROM_BASE(
  51. SUBSTR(
  52. TO_HEX(
  53. MD5(
  54. CAST(
  55. CAST(employers_test.user_id AS VARCHAR)
  56. AS VARBINARY
  57. )
  58. )
  59. )
  60. , 17, 10
  61. )
  62. , 16
  63. )
  64. AS DECIMAL(38, 0)
  65. )
  66. )
  67. )
  68. -- -
  69. ,
  70. SUM(DISTINCT
  71. (
  72. CAST(
  73. FROM_BASE(
  74. SUBSTR(
  75. TO_HEX(
  76. MD5(
  77. CAST(
  78. CAST(employers_test.user_id AS VARCHAR)
  79. AS VARBINARY
  80. )
  81. )
  82. )
  83. ,1,14
  84. )
  85. ,16
  86. )
  87. AS DECIMAL(38, 0)
  88. )
  89. *
  90. CAST(10000000000 AS DECIMAL(38, 0))
  91. +
  92. CAST(
  93. FROM_BASE(
  94. SUBSTR(
  95. TO_HEX(
  96. MD5(
  97. CAST(
  98. CAST(employers_test.user_id AS VARCHAR)
  99. AS VARBINARY
  100. )
  101. )
  102. )
  103. , 17, 10
  104. )
  105. , 16
  106. )
  107. AS DECIMAL(38, 0)
  108. )
  109. )
  110. )
  111. -- )
  112. -- /
  113. -- (1000000*1.0)
  114. -- , 0
  115. -- )
  116. -- ,0
  117. -- )
  118. AS "employers_test.appsflyer_install_count"
  119. FROM "td-presto".attribution.users_installs AS employers_test
  120. LEFT JOIN "td-presto".backend.users AS employers ON employers.id = employers_test.user_id
  121. LEFT JOIN "td-presto".backend.jobs AS jobs ON employers.id = jobs.job_owner_id
  122.  
  123. WHERE
  124. (((cast(employers_test.install_time as timestamp)) >= ((CAST(CONCAT(DATE_FORMAT(DATE_ADD('week', -3, DATE_TRUNC('DAY', DATE_ADD('day', (0 - MOD((DAY_OF_WEEK(CAST((NOW() AT TIME ZONE 'Europe/Luxembourg') AS DATE)) % 7) - 1 + 7, 7)), CAST((NOW() AT TIME ZONE 'Europe/Luxembourg') AS DATE)))), '%Y-%m-%d %T '), 'Europe/Luxembourg') AS TIMESTAMP))) AND (cast(employers_test.install_time as timestamp)) < ((CAST(CONCAT(DATE_FORMAT(DATE_ADD('week', 4, DATE_ADD('week', -3, DATE_TRUNC('DAY', DATE_ADD('day', (0 - MOD((DAY_OF_WEEK(CAST((NOW() AT TIME ZONE 'Europe/Luxembourg') AS DATE)) % 7) - 1 + 7, 7)), CAST((NOW() AT TIME ZONE 'Europe/Luxembourg') AS DATE))))), '%Y-%m-%d %T '), 'Europe/Luxembourg') AS TIMESTAMP)))))
  125. GROUP BY 1
  126. ORDER BY 1 DESC
  127. LIMIT 500
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement