Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
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 AI support!

Copy Clear