Sum only values if value of next day has the same value
<p>I have a table TAB1 and need to SUM values GROUP BY name column which is easy but I need to SUM only the values = 24 but only if the value with next date is 24 too.</p>

<p>St. like </p>

<pre><code>SELECT name, SUM(value) AS SUM_VALUE 
FROM TAB1 
WHERE value = 24 AND --next value of the same name with DATEADD(day,1,date) is 24 too
GROUP BY name
</code></pre>

<p>Thanks in advance for your help, regards Petr</p>

<pre><code>   name *date       *value  
    ***************************
    text1   *2016-06-01 *8
    text2   *2016-06-01 *4
    text1   *2016-06-02 *24
    text2   *2016-06-02 *8
    text1   *2016-06-03 *24
    text2   *2016-06-03 *24
    text1   *2016-06-04 *6
    text2   *2016-06-04 *24
    text1   *2016-06-05 *24
    text2   *2016-06-05 *24
    text1   *2016-06-06 *24
    text2   *2016-06-06 *8
    text1   *2016-06-07 *24
    text2   *2016-06-07 *24
    text1   *2016-06-08 *6
    text2   *2016-06-08 *24
    text1   *2016-06-09 *24
    text2   *2016-06-09 *24

calculation algorithm
1 - 48 =&gt; 0
2 - 72 =&gt; 24
1 - 72 =&gt; 24
2 - 72 =&gt; 24

The result should be

    name    *SUM_VALUE
    ******************
    text1   *24
    text2   *48
</code></pre>