Run Code
|
API
|
Code Wall
|
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
0
sample
project 1
PostgreSQL Sandbox: General Resale
hell
Select all countries that can be found by recursively adding all neighbouring countries (PostgreSQL)
conditionally add “another row” in SQL Server?
IF IN POSTGRESQL
1097. Game Play Analysis V
timestamp sample
Atuação