Created
January 14, 2018 20:08
Star
You must be signed in to star a gist
What is the average number of orders purchased across all vendors? What is the average cost across all vendors?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
avg(i.num_orders) as average_num_orders, | |
avg(i.subtotal) as average_subtotal | |
from ( | |
select | |
y.name, | |
count(distinct x.purchaseorderid) as num_orders, | |
sum(x.subtotal) as subtotal | |
from purchasing.purchaseorderheader x | |
left join purchasing.vendor y | |
on x.vendorid = y.businessentityid | |
group by y.name | |
) i; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment