Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- from
- (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
- from transactions
- where method = 'Delivery' and status = 'completed' and
- transactions.is_test = false
- group by 1,2
- order by order_count desc) as T1
- join
- (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
- from transactions
- where method = 'Delivery' and status = 'completed' and
- transactions.is_test = false
- group by month
- order by month) T2 on T1.month = T2.month
- order by month, order_count desc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement