Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PostreSQL: CASE
--PostgreSQL 9.6 --'\\' is a delimiter --create inventory table CREATE TABLE warehouse( product_id INT PRIMARY KEY NOT NULL, product VARCHAR (50), sku CHAR(50), upc INT NOT NULL, quantity INT NOT NULL ); --add records to table INSERT INTO warehouse (product_id, product,sku, upc, quantity) VALUES (1011, 'Mascara', 'A113M1', 3445-113-545, 540), (1012, 'Mascara', 'A212M2', 3445-212-454, 230), (1013, 'Nail Polish', 'A221NP2', 3445-221-43, 670), (1014, 'Nail Polish', 'A332NP2', 3445-332-003, 168), (1015, 'Lipgloss', 'A36LIPG',3445-336-347, 470); --CASE: If quantity is less than 300, reorder inventory --CASE: If quantity is greater than 300, do not reorder SELECT product_id, product, quantity, CASE WHEN quantity < 300 THEN 'reorder' WHEN quantity > 300 THEN 'stocked' END status FROM warehouse ORDER BY product_id;
run
|
edit
|
history
|
help
0
SQL - Social Network Analysis by Patrick Lin
Conditional Cross Join - Why doesn't this work on the 'ON' clause?
postgresql
find null in any column of table using PostgreSQL
Black Wall
Attributvariation 2
Timestamps in PostgreSQL
proj
Movie Rating SQL Analysis Project
PostreSQL: Right Outer Join