Add column in mysql with groupings

Asked

Viewed 27 times

0

How to select the total of requested amount to the sku_product?

inserir a descrição da imagem aqui

I tried to use DISTINCT to group the sku_product, and failed to add the requested quantity_quantity.

SELECT DISTINCT
(P.url_img1) AS url_img,
 (PPV.id_cliente) AS id_cliente,
  (PPV.sku_produto) AS sku_produto,
   (P.descricao_curta) AS descicao_produto,
    (PPV.valor_unit) AS valor_unit,
     (PPV.quantidade) AS quantidade_pedida,
      (P.quantidade) AS quantidade_saldo 
FROM pre_pedido PPV
JOIN produtos P ON PPV.sku_produto = P.sku 
WHERE id_cliente = '1' 
ORDER BY PPV.sku_produto
  • If you just think about the description, it would be basically select sku_product, sum(quantidade_pedida) from pre_pedido group by sku_produto , that is, sum the amount, group the sku. See if this already solves the problem

  • I followed your example simplifying the query and managed to get the desired result. I will post the answer with the correction in my code.

1 answer

0

I managed to solve with the code below;

SELECT 
          (P.url_img1) AS url_img,
        (PPV.id_cliente) AS id_cliente,
          (PPV.sku_produto) AS sku_produto,
        (P.descricao_curta) AS descicao_produto,
        (PPV.valor_unit) AS valor_unit,
        sum(PPV.quantidade) AS quantidade_pedida,
        sum(P.quantidade) AS quantidade_saldo
    FROM pre_pedido PPV 
    JOIN produtos P ON P.sku = PPV.sku_produto
    WHERE PPV.id_cliente = '1'
     group by PPV.sku_produto

Browser other questions tagged

You are not signed in. Login or sign up in order to post.