나는 이렇게 학습한다/Algorithm & SQL

GROCERY STORE: Support Local Products

daco2020 2022. 7. 7. 23:47
반응형

You are the owner of the Grocery Store. All your products are in the database, that you have created after CodeWars SQL excercises!:)

You care about local market, and want to check how many products come from United States of America or Canada.

Please use SELECT statement and IN to filter out other origins.

In the results show how many products are from United States of America and Canada respectively.

Order by number of products, descending.

products table schema

  • id
  • name
  • price
  • stock
  • producer
  • country

results table schema

  • products
  • country

 

Solution:

SELECT 
  COUNT(country) AS products, 
  country FROM products 
WHERE 
  country IN('United States of America', 'Canada') 
GROUP BY country
ORDER BY products DESC

 

Result:

products country
515 Canada
487 United States of America

 

반응형