Sorry for bad topic but I wasn't sure what to call it..
I have a table looking like this:
+-----++-----+
| Id ||Count|
+-----++-----+
| 1 || 1 |
+-----++-----+
| 2 || 5 |
+-----++-----+
| 3 || 8 |
+-----++-----+
| 4 || 3 |
+-----++-----+
| 5 || 6 |
+-----++-----+
| 6 || 8 |
+-----++-----+
| 7 || 3 |
+-----++-----+
| 8 || 1 |
+-----++-----+
I'm trying to make a select from this table where every time the SUM of row1 + row2 + row3 (etc) reaches 10, then it's a "HIT", and the count starts over again.
Requested output:
+-----++-----++-----+
| Id ||Count|| HIT |
+-----++-----++-----+
| 1 || 1 || N | Count = 1
+-----++-----++-----+
| 2 || 5 || N | Count = 6
+-----++-----++-----+
| 3 || 8 || Y | Count = 14 (over 10)
+-----++-----++-----+
| 4 || 3 || N | Count = 3
+-----++-----++-----+
| 5 || 6 || N | Count = 9
+-----++-----++-----+
| 6 || 8 || Y | Count = 17 (over 10..)
+-----++-----++-----+
| 7 || 3 || N | Count = 3
+-----++-----++-----+
| 8 || 1 || N | Count = 4
+-----++-----++-----+
How do I do this, and with best performance? I have no idea..
dense_rank()doesn't do the trick, you could do this with a recursive view as well. I believe thatdense_rank()route would be better optimized though.