반응형
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 |
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
SQL Basics: Simple EXISTS (0) | 2022.07.09 |
---|---|
GROCERY STORE: Real Price! (0) | 2022.07.08 |
SQL with Sailor Moon: Thinking about JOINs... (0) | 2022.07.06 |
SQL with Pokemon: Damage Multipliers (0) | 2022.07.05 |
SQL: Concatenating Columns (0) | 2022.07.04 |