Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. with syncs_per_table as
  2. (
  3. select schema_name || '.' || table_name as schema_table, monthly_rows_synced
  4. from
  5. (
  6. select schema_name, table_name, round(30.42/14*total_rows_synced) as monthly_rows_synced
  7. from
  8. (
  9. select
  10. "schema" as schema_name, "table" as table_name,
  11. sum(rows_updated_or_inserted) as total_rows_synced
  12. from products_products.fivetran_audit
  13. where done >= '2016-08-08' and done < '2016-08-22'
  14. group by schema_name, table_name
  15. )
  16. union
  17. (
  18. select
  19. "schema" as schema_name, "table" as table_name,
  20. sum(rows_updated_or_inserted) as total_rows_synced
  21. from like2buy_like2buy.fivetran_audit
  22. where done >= '2016-08-08' and done < '2016-08-22'
  23. group by schema_name, table_name
  24. )
  25. union
  26. (
  27. select
  28. "schema" as schema_name, "table" as table_name,
  29. sum(rows_updated_or_inserted) as total_rows_synced
  30. from reels_web.fivetran_audit
  31. where done >= '2016-08-08' and done < '2016-08-22'
  32. group by schema_name, table_name
  33. )
  34. union
  35. (
  36. select
  37. "schema" as schema_name, "table" as table_name,
  38. sum(rows_updated_or_inserted) as total_rows_synced
  39. from reveal_widgets.fivetran_audit
  40. where done >= '2016-08-08' and done < '2016-08-22'
  41. group by schema_name, table_name
  42. )
  43. union
  44. (
  45. select
  46. "schema" as schema_name, "table" as table_name,
  47. sum(rows_updated_or_inserted) as total_rows_synced
  48. from web_campaigns.fivetran_audit
  49. where done >= '2016-08-08' and done < '2016-08-22'
  50. group by schema_name, table_name
  51. )
  52. union
  53. (
  54. select
  55. "schema" as schema_name, "table" as table_name,
  56. sum(rows_updated_or_inserted) as total_rows_synced
  57. from web_permissions.fivetran_audit
  58. where done >= '2016-08-08' and done < '2016-08-22'
  59. group by schema_name, table_name
  60. )
  61. union
  62. (
  63. select
  64. "schema" as schema_name, "table" as table_name,
  65. sum(rows_updated_or_inserted) as total_rows_synced
  66. from web_web.fivetran_audit
  67. where done >= '2016-08-08' and done < '2016-08-22'
  68. group by schema_name, table_name
  69. )
  70. )
  71. )
  72.  
  73. select schema_table, monthly_rows_synced, total_volume, 100.0*monthly_rows_synced/total_volume as pcnt_volume
  74. from
  75. (
  76. select *
  77. from syncs_per_table
  78. )
  79. inner join
  80. (
  81. select sum(monthly_rows_synced) as total_volume
  82. from syncs_per_table
  83. )
  84. on 1=1
  85. order by monthly_rows_synced desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement