Home > database >  Sum of quantity column based on the grouped of product_id column values with their respective names
Sum of quantity column based on the grouped of product_id column values with their respective names

Time:10-10

Here is what my table looks like:

Here is what my table looks like

Here what I need:

Here what I need

I tried this code

SELECT DISTINCT(product_id), 
    SUM(quantity) OVER (PARTITION BY product_id) AS sumquantity     
FROM ord1;

CodePudding user response:

GROUP BY will do the trick in this case!

SELECT emp, name, product, SUM(quantity) 
FROM ord1
GROUP BY emp, name, product
ORDER BY emp, name, product

Replace the column names with the ones from your database table.

  •  Tags:  
  • sql
  • Related