나는 이렇게 학습한다/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

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Sum of angles  (0) 2022.06.22
SQL Basics: Up and Down  (0) 2022.06.21
Best-Selling Books (SQL for Beginners #5)  (0) 2022.06.19
SQL Basics: Simple table totaling.  (0) 2022.06.18
SQL Basics: Simple IN  (0) 2022.06.17