1

I have a query with multiple sum that create a new column. But I have to add a sum of the result of one.

I put sum (TOTALPIEZAS *2) AS test

SELECT
   Lote_Cliente.cliente,
   Lote_Cliente.numero_lote_cliente,
   Produccion.Longitud,
   Produccion.Anchura,
   Produccion.Espesor,
   COUNT(Lote_Cliente.numero_lote_cliente) AS Pales,
   SUM(Produccion.Kilos) AS Peso,
   SUM(Produccion.Piezas) AS TOTALPIEZAS,
   SUM (TOTALPIEZAS *2) AS test,
   CONCAT((Longitud*10), 'x', (Anchura*10),'x',Espesor) AS FINALTAMAÑO
FROM
   Lote_Cliente
INNER JOIN
   Produccion ON Lote_Cliente.numero_lote_cliente = Produccion.Lote_cliente
WHERE
   (Lote_Cliente.fecha_preparacion BETWEEN '2019-06-20' AND '2019-06-20') 
   AND (Produccion.Producto = 'Pizarra')
GROUP BY
   Lote_Cliente.numero_lote_cliente, FINALTAMAÑO

A column test with the result of TOTELPIEZAS * 2

1 Answer 1

1

You can't use a column alias in select .. because the column alias is not avalaible at this moment
You should calculate the sum for produccion.Piezas*2

COUNT(Lote_Cliente.numero_lote_cliente) AS Pales,
SUM(Produccion.Kilos) AS Peso,
SUM(Produccion.Piezas) AS TOTALPIEZAS,
SUM (Produccion.Piezas*2) AS test,
Sign up to request clarification or add additional context in comments.

1 Comment

I dont thinks this before. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.