I'm trying to convert the result I get from a query but I'm totally lost.
I'm fetching data from an orders table, the sql looks like:
select
ped_pedidos.id_escuela,
escuelas.nombre,
provincias.descripcion,
if(ped_pedidos.id_tipo = 3, ped_pedidos.total_pedido*-1, ped_pedidos.total_pedido) as total,
ped_productos.descripcion,
ped_pedidos_lineas.cantidad as t_pedido
from ped_pedidos
left join escuelas on ped_pedidos.id_escuela = escuelas.id
left join provincias on escuelas.id_provincia = provincias.id
left join ped_pedidos_lineas on ped_pedidos_lineas.id_pedido = ped_pedidos.id
left join ped_productos on ped_productos.id = ped_pedidos_lineas.id_producto
where ped_pedidos.curso = '2017' and ped_pedidos.id_estado = 2
group by ped_pedidos.id
And I'm getting the following data:
+------------+--------+-------------+----------+-------------------+----------+--+
| id_escuela | nombre | descripcion | total | descripcion | cantidad | |
+------------+--------+-------------+----------+-------------------+----------+--+
| 628 | fake 1 | Girona | 23726.50 | Product Wonder 1 | 54 | |
| 613 | fake 2 | Granada | 1934.50 | Product Great 2 | 26 | |
| 457 | fake 3 | Barcelona | 2210.00 | Product Awesome 3 | 65 | |
| 628 | fake 1 | Girona | 23726.50 | Product Great 2 | 15 | |
+------------+--------+-------------+----------+-------------------+----------+--+
I would like to convert this to the following:
+------------+--------+-------------+----------+------------------+-----------------+-------------------+
| id_escuela | nombre | descripcion | total | Product Wonder 1 | Product Great 2 | Product Awesome 3 |
+------------+--------+-------------+----------+------------------+-----------------+-------------------+
| 628 | fake 1 | Girona | 23726.50 | 54 | 15 | 0 |
| 613 | fake 2 | Granada | 1934.50 | 0 | 26 | 0 |
| 457 | fake 3 | Barcelona | 2210.00 | 0 | 0 | 65 |
+------------+--------+-------------+----------+------------------+-----------------+-------------------+
Is it possible or I'm trying to do something that can't be done?