title: postgresql mathematical formula error
body: <p>Hi I am trying to use a mathematical function on each row in postgresql.
  But It gives me a error.
  <br>My Query:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>On this Query It gives me a error: column <em>qty_sold</em> doesn't exist.
  If i change the 5th line to <br></p>
  
  <pre><code>(stock_inventory_line.product_qty / COUNT(sale_order_line.name)) AS NOM
  </code></pre>
  
  <p>It gives me an error: Aggregate functions not allowed in group by.</p>