Skip to content
Advertisement

SQL few running total at different stops

Note: I am bringing up a problem to which I have a solution, the purpose of the question is to see if there is a better one.

I have customers that make transactions. I want for each customer to know when did they reach 3K, 5K and 7K (or any other threshold). End result is:

enter image description here

I was wondering if I have a better way to do it, other then copying the same CTE each time. This is the code:

Advertisement

Answer

You cqan combine the 3 subquereis to one with condition aggregation

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement