SQL help case statement

mc
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`,
case
when `splind = '1'
then
sum((`transactions`)/`MV`)*100 as "splind1"
when `splind` != '1'
then
sum((`transactions`)/`MV`)*100 as "splindnot1"
else
sum((`transactions`)/`MV`)*100 as "splind_all"
FROM `twoyears`
group by
 `acct`, `name`,`country`

0 Kudos
2 Replies
JeanBaptiste
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.

mc
Level 2
Author

Thanks for ur response. Okay!

0 Kudos