Question: I have a requirement where in i need to find the lowest and non repeating value in a sql column. Let me describe it

```
Sno. User amount
1.   1001 $0.02
2.   1002 $0.03
3.   1003 $0.04
5.   1004 $0.02
6.   1005 $0.05

```

In this scenario, in the amount column although $0.02 is the minimum, but we can see that it is also preset twice(repeating) in the column, so the next minimum and non repeating value is $0.03 and which is what I want.
I tried using Distinct but it gives all the values in the amount column I just need the one. I don't care about the higher values $0.04 and $0.05 here.

Answer: 
What you need is *conditional aggregation*:

```
select ......,   sum(case when amount < 0 then amount end) as credits,
                 sum(case when amount > 0 then amount end) as debits
from   ......
group by account_number

```
**Create an Expression Which Checks for Sign of Amount (and NULLS) and Assigns a Non-NULL Value and Sums**

I just make sure that my expression is non-NULL (all records have a non-NULL numeric assignment) and then I sum.

Being primarily an Oracle SQL developer, I am biased towards Oracle functions such as `decode` and `sign`.

```
     SCOTT@dev>WITH test_data AS (
  2      SELECT
  3          4.32 amount, '100' account
  4      FROM
  5          dual
  6      UNION ALL
  7      SELECT 3.23, '100'
  8      FROM
  9          dual
 10      UNION ALL
 11      SELECT
 12          -3.22, '100'
 13      FROM
 14          dual
 15      UNION ALL
 16      SELECT
 17          -4.22, '100'
 18      FROM
 19          dual
 20      UNION ALL
 21      SELECT
 22          4.22, '200'
 23      FROM
 24          dual
 25      UNION ALL
 26      SELECT
 27          0, '200'
 28      FROM
 29          dual
 30      UNION ALL
 31      SELECT
 32          NULL, '200'
 33      FROM
 34          dual
 35  ) SELECT
 36      account,
 37      SUM(DECODE( sign(nvl( amount, 0) ), 1, amount, 0) ) debits,
 38      SUM(DECODE( sign(nvl( amount, 0) ), -1, amount, 0) ) credits
 39  FROM
 40      test_data
 41  GROUP BY
 42      account;
ACCOUNT  DEBITS  CREDITS  
100      7.55    -7.44    
200      4.22    0    

```