Finding the maximum sum of a column for any 3 rows in SQL Server
<p>I would like to ask the following question</p>

<p>I have a table with many rows and the following columns</p>

<pre><code>sender, recipient, value
</code></pre>

<p>For example </p>

<pre><code>sender  recipient   value
smith   williams     500
smith   taylor       100
smith   vagelis      200
vagelis taylor       150
giorgos taylor       150
nikos   taylor       200
smith   Kostas       300
</code></pre>

<p>I would like to find the maximum sum of values for any 3 rows and for all specific senders.</p>

<p>In my example</p>

<pre><code>smith   800
giorgos 150
vagelis 150
nikos   200
</code></pre>

<p>And finally to find all the senders that their maximum sum for any 3 rows is above 500.This is my finally goal.</p>

<p>In my example</p>

<pre><code>smith 800
</code></pre>

<p>Thank you in advance</p>

<p><strong>Update</strong>
I found the solution with the help of @Prdp post</p>

<pre><code>select distinct a.sender,a.total_sum from(
 SELECT t1.sender,(t1.value+ t2.value + t3.value)
       as total_sum
    FROM    
    transfers2  t1, transfers2 t2, transfers2 t3
          where 
              t1.sender = t2.sender
           and t3.sender = t2.sender
             and t1.date!=t2.date 
             and t1.date!=t3.date
             and t2.date!=t3.date
             ) a
             where a.total_sum&gt;500
</code></pre>