I have a table in my SQL Server database with the following contents in it:
Date | Amount ------------|---------- 2012-12-17 | 9.00 2012-12-18 | 8.00 2012-12-19 | 0.00 2012-12-20 | 1.50 2012-12-21 | 2.50 2012-12-22 | 0.00 2012-12-23 | 0.00 2012-12-24 | 0.00 2012-12-25 | 0.00 2012-12-26 | 4.00 2012-12-27 | 2.00 2012-12-28 | 7.00
What I want to do is take 3 lines to choose from and SUM Amount . If the total SUM is 0 , then it should delete these 3 entries. Otherwise, he should just leave them alone and make the next 3 entries and make the same checks.
So, in this case, only the next three records should be deleted from the table, since they are the only ones where SUM will lead to 0 .
2012-12-23 | 0.00 2012-12-24 | 0.00 2012-12-25 | 0.00
How can I do it in SQL Server?
source share