Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. select T1.month, T1.rest, T1.order_count, T2.total_orders, to_char(100 * (T1.order_count::float / T2.total_orders), '999D99%') as perc_vol
  2. from
  3. (select to_char(transactions.delivered_at_est, 'YYYY-MM') || ' (' || trim(trailing ' ' from to_char(transactions.delivered_at_est, 'Month')) || ')' as month, transactions.company_name as rest, count(distinct transactions.id) as order_count
  4. from transactions
  5. where method = 'Delivery' and status = 'completed' and
  6. transactions.is_test = false
  7. group by 1,2
  8. order by order_count desc) as T1
  9.  
  10. join
  11. (select to_char(transactions.delivered_at_est, 'YYYY-MM') || ' (' || trim(trailing ' ' from to_char(transactions.delivered_at_est, 'Month')) || ')' as month, count(distinct transactions.id) as total_orders
  12. from transactions
  13. where method = 'Delivery' and status = 'completed' and
  14. transactions.is_test = false
  15. group by month
  16. order by month) T2 on T1.month = T2.month
  17. order by month, order_count desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement