I am doing a query in mysql which has to print the location_bm columns with the number of products in each column, try something like this but it happens that it prints only one record and in all columns it gives me the same result.
As seen in my query, I make several cases and my idea is to add the sum of the products depending on whether the product is in the location but it is not working correctly
SELECT transformadores.ubicacion_bm,
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'POSTE 3F',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'POSTE 1F',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'ESTACION',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'SECOS 1F',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'SECOS 3F',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'PEDESTAL 1F',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'PEDESTAL 3F',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'CONTROL',
case
when (TIPO = 'TND' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNE' AND FASE ='3F') then SUM(QMANO)
when (TIPO = 'TNM' ) then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNP' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '3F') then SUM(QMANO)
when (TIPO = 'TNS' AND FASE = '1F') then SUM(QMANO)
when (TIPO = 'TNZ') then SUM(QMANO)
END as 'TOTAL'
FROM transformadores where (ALMACEN_REP = ('BM')) AND ubicacion_bm in ('ZONA 2',' EXHIBICION INTERNA','ZONAS','JAULA DE OPERACIONES')
order by ID desc;
I leave a link to see the image enter image description here