Or it could be really easy...dunno..
Either way,
I have a database with product ID's. I want to select the most commonly x occuring instances of a paticular ID. where x is say, the top 10 most occuring and then in another table i have the the product cost and I only need to select the most commonly occuring under a certian price. how would I do this with sql? it seems like something there'd be a built in function for. any ideas?
semi-complex sql problem
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
this worked for me..
Code: Select all
SELECT DISTINCT order_items.product_id, products.id, COUNT( products.id ) , products.price
FROM order_items, products
WHERE products.price <=50
GROUP BY order_items.product_id
ORDER BY COUNT( products.id ) DESC
LIMIT 50