SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table products ( id int primary key auto_increment, product_id int, name varchar(64), variant varchar(64), price decimal(9,2) ); insert into products (product_id, name, variant, price) select coalesce ( min(case when name = 'мышь' then product_id end ), coalesce(min(product_id), 0) + 1 ) product_id ,'мышь', 'красная', 150 from products; insert into products (product_id, name, variant, price) select coalesce ( min(case when name = 'мышь' then product_id end ), coalesce(min(product_id), 0) + 1 ) product_id ,'мышь', 'синяя', 150 from products; insert into products (product_id, name, variant, price) select coalesce ( min(case when name = 'мышь' then product_id end ), coalesce(min(product_id), 0) + 1 ) product_id ,'мышь', 'белая', 150 from products; insert into products (product_id, name, variant, price) select coalesce ( min(case when name = 'белка' then product_id end ), coalesce(min(product_id), 0) + 1 ) product_id, 'белка', 'белая', 150 from products; insert into products (product_id, name, variant, price) select coalesce ( min(case when name = 'белка' then product_id end ), coalesce(min(product_id), 0) + 1 ) product_id, 'белка', 'красная', 150 from products; /*1 0 мышь красная 150 2 0 мышь синяя 150 3 0 мышь белая 150*/ select * from products;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear