Hi I am trying to use a mathematical function on each row in postgresql.
But It gives me a error.
My Query:
Select
stock_inventory_line.product_code AS Sku,
COUNT(sale_order_line.name) AS Qty_Sold,
stock_inventory_line.product_qty AS Current_Qty,
(stock_inventory_line.product_qty / Qty_Sold) AS NOM
From
sale_order_line,
product_product,
product_template,
product_category,
stock_inventory_line
WHERE
sale_order_line.product_id = product_product.id AND
product_product.product_tmpl_id = product_template.id AND
product_template.categ_id = product_category.id AND
product_product.default_code = stock_inventory_line.product_code
GROUP BY
Sku,
Current_Qty,
NOM;
On this Query It gives me a error: column qty_sold doesn't exist.
If i change the 5th line to
(stock_inventory_line.product_qty / COUNT(sale_order_line.name)) AS NOM
It gives me an error: Aggregate functions not allowed in group by.