I’m trying to add a column based on the result of the following string:
SELECT product_code AS "Product Code", SUM(quantity) AS "Quantity"
FROM receipts_items
GROUP BY product_code
ORDER BY SUM(quantity) DESC
this string gives me a Product Code and the quantity sold. What I need to add is, based on the product code, the description of that product code.
product_code and descriptions column are in the same table “products”
quantity is in another table “receipts_items”
Thanks!!!
You want to
JOINthe two tables onproduct_code.You really ought to do a
LEFT JOINto catch products with no associated receipt items, then put aCASEstatement in yourSUMto reduceNULLvalues to 0.