Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

SQL help case statement

Level 2
SQL help case statement

Greetings all, Obviously there is a syntax error, is there some one who can correct? 

I am expecting a result set with columns acct, name, country, splind1, splindnot1, splind_all.

Much appreciated!

SELECT `acct`, `name`,`country`,
when `splind = '1'
sum((`transactions`)/`MV`)*100 as "splind1"
when `splind` != '1'
sum((`transactions`)/`MV`)*100 as "splindnot1"
sum((`transactions`)/`MV`)*100 as "splind_all"
FROM `twoyears`
group by
 `acct`, `name`,`country`

0 Kudos
2 Replies
Level 3

Hi @mc ,

I don't think you can output three different fields in one case statement.

From what I understand, you can have only one of the three values (splind1, splindnot1, splind_all) for a row.

You need to create the three fields using one case statement for each one of them, computing the value when it satisfies the condition and specifying a null value when it doesn't.

Level 2

Thanks for ur response. Okay!

0 Kudos