cancel
Showing results for 
Search instead for 
Did you mean: 

CASE WHEN equivalent in SQLSCRIPT

Former Member
0 Kudos

Hello everybody,

I am new to this forum, maybe somebody can help me

At it's core, I want to create a calculation view that calculates count() of different values for one column

in SQL, I was able to solve the problem with the following code:

SELECT "Id", count(case when "TA_TYPE"='StrongPositiveSentiment' then 1 end) as "SPS",

count(case when "TA_TYPE"='WeakPositiveSentiment' then 1 end) as "WPS",

count(case when "TA_TYPE"='Sentiment' then 1 end) as "S",

count(case when "TA_TYPE"='WeakNegativeSentiment' then 1 end) as "WNS",

count(case when "TA_TYPE"='StrongNegativeSentiment' then 1 end) as "SNS"

FROM "GBI_011"."$TA_GRUPPE_3_ENGLISH_IDX"

GROUP BY "Id"


The corresponding output looks like this:




Now, I want to create the same in a calculation view with SQLScript, but it seems the same code doesnt work there. I want to group by "Id" and get the count() values for different entries in "TA_TYPE", e.g Sentiment, WeakPositiveSentiment etc... in the calculation view


any suggestions? I hope I made my problem clear


Greetings

Daniel


Accepted Solutions (1)

Accepted Solutions (1)

lucas_oliveira
Advisor
Advisor
0 Kudos

Hi Daniel,

What you mean by 'it seems the same code doesn't work there'? I can't see why it wouldn't work but is there any error message you're facing?

Maybe post your actual sqlscript code so we can look at it. If you have some small sample data that helps even further.

BRs,

Lucas de Oliveira

Former Member
0 Kudos

Hi Lucas, 

sure I can provide it:

Here is an  excerpt from my data: the TA_TYPE sometimes has 'Sentiment' or 'WeakPositiveSentiment' entries which i want to count...

Hope its clearer now!

Thanks in Advance for the help!

lucas_oliveira
Advisor
Advisor
0 Kudos

Hm, I'm guessing you're already counting them so why set the aggregation as count (from second image, column 'Aggregation')?

Change those to sum.

BRs,

Lucas de Oliveira

Former Member
0 Kudos

Hi Lucas,

I did as you  said and this is the output:

In other words:  IT WORKS PERFECTLY thanks a lot for your help

anindya_bose
Active Contributor
0 Kudos

Hi Daniel

Please mark the question as "Answered" ( for the reply which resolved your issue) , that's the way to say thanks here 

Regards

Anindya

Answers (0)