sql server - Complicated SQL query for a running total column -


I am trying to work on a very complex query in SQL Server 2008. I need some input from SQL experts

Imagine I had a payment table with these areas:

PaymentID integer, CustomerID integer, PaymentDate date, zodiac decimal

Essentially, this A table is an important thing of payments made by a customer on specific dates, in some cases, the payment amount can be a negative value. Therefore, over time, the total amount paid by any customer can go up or down

If we have paid 3, then first: for $ 5, the data we try to remove It is SQL, which calculates the high points of the total amount paid per customer.

Second, third - $ 3 for $ 5 will be shown in the report that Fred's total payment amount was $ 10 (on his second payment), and his last payment amount was $ 7.

We report this report to one million customers (possibly one hundred to one thousand rupees each), so it has become faster.

Is this a good way to structure this query without processing the DB running? If we want to avoid accumulation of precalculated values ​​possible,

Your question is going on: / P>

  Select Customer ID, SM (Amount) from the table where the amount & gt; CustomerID Selection CustomerID by Group 0, CUSTOMERID from SUM (Zodiac) Table Group  

However, I think that you mean that you want a table that looks like this

  Customer Payments Highpoint RunningTotal 123 5 5 5 123 5 10 10 123 -3 10 7 In which case I am up to which something like the scene There are two choices to make a scene with.  
  Select CusotmerID, PaymentDate, Zodiac, (As Selection Sum (Amount) Alias ​​from ALIAS.Amount & gt; 0 and ALIAS.PaymentDate & lt; = PaymentDate and ALIAS .CustomerID = CustomerID), select the sum (zodiac) as the nickname ALIAS.CustomerID = CustomerID and ALIAS.PaymentDate from & lt; = PaymentDate) from the table  

its Besides, you can consider a non-unique index to give the speed of the view to the amount of table column.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -