Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess DB do line item calculation on total of a column before knowing the total
    primarykey
    data
    text
    <p><strong>[ edit ]</strong></p> <p>For the record, here's the problem portion of the query, which is now working:</p> <pre><code>SELECT m.groupNum, t.ea, ( t.ea - ( t.ea * m.margin )) AS estCost, (( t.ea - ( t.ea * m.margin )) * t.quantity ) AS salesSub, ((( t.ea - ( t.ea * m.margin )) * t.quantity ) / ( SELECT SUM(( t2.ea - ( t2.ea * m.margin )) * t2.quantity ) FROM temp as t2 INNER JOIN masters as m2 ON t2.mod = m2.mod WHERE m2.groupNum = m.groupNum ) ) AS salesPercent etc... </code></pre> <p><strong>[ end edit ]</strong></p> <p>I think I need a query that can recursively update itself based on the total of a column's values after inserting values on all the rest of the records for a given (groupNum) range.</p> <p>I already have the estCost and salesSub fields. Now I need to do calculations on the <strong>salesPercent</strong> field, which involves knowing the total amount of all salesSub records in a given set (groupNum). </p> <pre><code>salesPercent = ( salesSub / [the sum total of all salesSub amounts for each groupNum] ) </code></pre> <p><em>(snip)</em></p> <pre><code>SELECT m.id, t.priceEach, ( t.priceEach - ( t.priceEach * m.margin )) AS estCost, (( t.priceEach - ( t.priceEach * m.margin )) * t.quantity ) AS salesSub -- is it possible to perform calculation on salesPercent here? INTO output FROM financeMasters AS m INNER JOIN temp AS t ....... </code></pre> <p><em>(end snip)</em></p> <p>I have this...</p> <pre><code>------ output --------------------------------------------------------------- id | groupNum | priceEach | estCost | salesSub | salesPercent | --------------------------------------------------------------- 1 | apple | 150.00 | 90.00 | 90.00 | 2 | apple | 100.00 | 60.00 | 60.00 | 3 | apple | 50.00 | 30.00 | 30.00 | </code></pre> <p>but how can I calculate salesPercent on the salesSub total (in this case 180.00) before knowing the total?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload