I'm trying to make a sql request on Oracle but i'hve a little probleme. I've this sentence to translate and I don't know how.. Can you help me ? How can I translate it ? :(
IF(CODE="fuu")
THEN(SELECT bar FROM TABLE)
ELSE(we return 0)
Thx in advice.
EDIT :
My request is like that
SELECT distinct
A, B, C, D, E,
SUM(F+G+H) AS "FGH",
SUM(I -(FGH)) AS "I",
CASE WHEN code='fuu' THEN bar ELSE 0 END AS AS "What I need"
FROM
TABLE
WHERE
A=20
GROUP BY
A, B, C, D, E;
This solution works but i'don't have the good answer for it. Actually is should have for A=20 -> bar = 7598 and not 0;
An IF-THEN statement can be followed by an optional ELSIF...ELSE statement.
Conditional selection statements, which run different statements for different data values. The conditional selection statements are IF and CASE . Loop statements, which run the same statements with a series of different data values. The loop statements are the basic LOOP , FOR LOOP , and WHILE LOOP .
An IF statement can have any number of ELSIF clauses; the final ELSE clause is optional.
A case expression in SQL is an equivalent to IF statement in other languages:
CASE WHEN condition THEN value1 [ ELSE value2 ] END
I guess that you are looking for something like this:
SELECT distinct
A, B, C, D, E,
SUM(F+G+H) AS "FGH",
SUM(I -(FGH)) AS "I",
CASE WHEN CODE='fuu' THEN bar ELSE 0 END As "What I need"
FROM
TABLE
WHERE
A=20
GROUP BY
A, B, C, D, E, "What I need"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With