Skip to content
Advertisement

Sum of quantity column based on the grouped of product_id column values with their respective names form name column

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;

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement