How to identify positive minimum or negative maximum in a column for a key?
<p>I have the following columns - Person_ID Days. For one person id, multiple days are possible. Something like this:</p>

<pre><code>Person_Id Days
1000      100
1000      200
1000      -50
1000      -10
1001      100
1001      200
1001       50
1001       10
1002      -50
1002      -10
</code></pre>

<p>I need to address the following scenarios:</p>

<p>If all values for days column are positive, I need minimum of the days for a person_id. If the days column has both positive and negative, I need minimum of positive. If all negatives, I need maximum of negative.</p>

<p>The output like:</p>

<pre><code>Person_id Days
1000      100
1001       10
1002      -10
</code></pre>

<p>I tried using case statement, but I am unable to use a same column in the condition as well as grouping. </p>