나는 이렇게 학습한다/Algorithm & SQL
GROCERY STORE: Inventory
daco2020
2022. 6. 20. 19:28
You are the owner of the Grocery Store. All your products are in the database, that you have created after CodeWars SQL excercises!:)
Today you are going to CompanyA warehouse
You need to check what products are running out of stock, to know which you need buy in a CompanyA warehouse.
Use SELECT to show id, name, stock from products which are only 2 or less item in the stock and are from CompanyA.
Order the results by product id
products table schema
- id
- name
- price
- stock
- producent
results table schema
- id
- name
- stock
Solution:
SELECT
id, name, stock
FROM
products
WHERE
stock <= 2 and producent = 'CompanyA'
ORDER BY id
Result:
id | name | stock |
39 | Borlotti Beans | 1 |
46 | Snowpea sprouts | 2 |
49 | Apples | 0 |