Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PostgreSQL: 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
1
Please
log in
to post a comment.
cpana
Query workaround in order to avoid IN Operator in WHERE Clause
HW1
Current time/date, timezone
loggin_trigger-audit
prec
Assignment
postgresql
postgresql example hierarchy with addresses
Pivot the Hard Way.
Please log in to post a comment.