I am trying to perform a query in SQL Developer (Oracle) on several tables. In which I need to compare the result of expression if it is Greater or Equal (x> = 0) or if it is Minor:
X >= 0 => Resultado: 'S' ; X < 0 => Resultado: 'N'
And I also need to put a range of values on an expression that is:
x > 100 => Resultado: 100 ; x < 0 => Resultado 0 ; 0 =< x =< 100 => Resultado: X
I tried to do it through CASE Expressions but I have not received the expected result The query in question is the following:
SELECT cns.DIA,
SUM(vs.NETO),
SUM(cns.GASTO),
SUM(t.ASIG),
SUM(cns.GASTO)-(SUM(t.ASIG)/SUM(vs.NETO) AS X,
CASE SUM(cns.GASTO)-(SUM(t.ASIG) + SUM(vs.NETO)) WHEN 0 THEN 'S'
ELSE 'N' END AS USO
FROM T1.CONSUMO cns,
T2.VOLSERV vs,
T3.TRANS t;
RESULT OBTAINED
DIA NETO GASTO ASIG USO
19/08/2017 70000 115080 50000 N
I would have to receive an 'S' since it spent more than the account.
Greetings .-