Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter Performance for calculating running total Operation in sql server 2005
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/17825830/update-table-data-without-using-while-loop-in-sql-server-2005">Update table Data without using while loop in sql server 2005</a></p> <p>i asked this question and Details are....</p> <p>in sql i have table data like below</p> <pre><code>id type amount 1 type1 2000 2 type1 1000 3 type2 500 4 type3 3000 5 type1 2000 6 type2 500 7 type3 5000 8 type1 1000 </code></pre> <p>and i want to get datas in select statement like below </p> <pre><code>id type amount current 1 type1 2000 2000 2 type1 1000 1000 3 type2 500 500 4 type3 3000 3000 5 type1 2000 3000 6 type2 -500 0 7 type3 5000 2000 8 type1 -1000 4000 </code></pre> <p>and so on that means each type must have its current total amount based on amount type and its need to be dont have while loop because it takes long time to execute</p> <pre><code>for eg: in type 1 ID Amount current 1 2000-add 2000 2 1000-sub 1000 3 2000-add 3000 4 1000-add 4000 </code></pre> <p>and the answer is,</p> <pre><code>SELECT id, type, amount, (SELECT sum(amount) FROM mytable t1 WHERE t1.type = t2.type AND t1.id &lt;= t2.id) currenttotal FROM mytable t2 </code></pre> <p>Now problem is assume the example table have 8000(it will Increase) records of Data like</p> <pre><code>id type amount 1 type1 2000 2 type1 1000 3 type2 500 4 type3 3000 5 type1 2000 6 type2 500 7 type3 5000 8 type1 1000 </code></pre> <p>and its take <code>00:00:02</code> time for execute the select statement which i written based on the answer(have 2 answers and both have same execution time) for above question.How to reduce this time of execution?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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