Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carloswm85/58dc04102ccd3e7be69e4a0978ba0490 to your computer and use it in GitHub Desktop.
Save carloswm85/58dc04102ccd3e7be69e4a0978ba0490 to your computer and use it in GitHub Desktop.

This is the solution. Be sure that you've spent a good chanck of your time trying out your own approaches before using this solution.

-- 3. How many of each category of bikes do we have in our "Baldwin Bikes" store, which has the store_id of 2.
-- We need to see the name of the category as well as the number of bikes in the category.
-- Sort it by lowest numbers first. 
USE bike;
USE bike;
SELECT * FROM category;
SELECT * FROM product;
SELECT * FROM stock;
SELECT * FROM store;

SELECT category_name,count(quantity) as 'instock'
	FROM category c
    JOIN product p ON c.category_id = p.category_id
    JOIN stock sk ON sk.product_id =  p.product_id
    JOIN store st ON sk.store_id = st.store_id
WHERE sk.store_id = 2 -- filtering
GROUP BY p.category_id
ORDER BY count(quantity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment