Wednesday, 21 August 2013

mysql avg on multiple inner join

mysql avg on multiple inner join

I have the following query:
SELECT ROUND(AVG( p.price ),2) as Avg_value
FROM quotes
inner join `system_users`
ON quotes.created_by = system_users.id
inner join quote_items s
ON s.quote_id = quotes.id
inner join new_products p
ON p.id = new_product_id
how do you determine what the average is being based on seeing that: a
system user can have many quotes and a quote can have many quote items
each quote item has one product.
I'd like the average to be based on the number of quotes. how would the
query have to be changed for it to be based on the number of quote_items
Thanks

No comments:

Post a Comment