SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table orders ( id int primary key, name varchar(64), price decimal(9, 2) ); insert into orders values (1, 'Order 1', 1000), (2, 'Order 2', 2000); create table order_attributes ( id int primary key, order_id int, attrib_id int, attrib_name varchar(64), attrib_value varchar(64) ); insert into order_attributes values (1, 1, 101, 'цвет', 'красный'), (2, 1, 102, 'размер', '100'), (3, 1, 103, 'дата', '30-10-2023'), (4, 2, 101, 'цвет', 'зеленый'), (5, 2, 102, 'размер', '300') ; select o.id, o.name, o.price, group_concat(case when attrib_name = 'цвет' then attrib_value end) color, group_concat(case when attrib_name = 'размер' then attrib_value end) size, group_concat(case when attrib_name = 'дата' then attrib_value end) date from orders o left join order_attributes oa on o.id = oa.order_id group by o.id, o.name, o.price;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear