Results 1 to 8 of 8
Jan 13, 2010, 21:24 #1
- Join Date
- Jan 2006
- 0 Post(s)
- 0 Thread(s)
Need help with creating a view query
I'm trying to sort products on my website by their sales volume. My thought is to create a view that tabulates the quantity sold by product_id over the past 180 days.
I've got a question regarding the query:
SELECT p.products_id, COUNT( op.products_id ) AS num_ordered FROM orders_products op JOIN products p JOIN orders AS o WHERE op.products_id = p.products_id AND o.orders_id = op.orders_id AND ( TO_DAYS( NOW( ) ) - TO_DAYS( o.date_purchased ) ) <180 GROUP BY p.products_id ORDER BY num_ordered DESC
Assuming we figure that out, is a view and efficient way to tabulate these results? Would the view automatically be updated whenever a new product is added or a product is ordered? I'm a noobie when it comes to views...