cancel
Showing results for 
Search instead for 
Did you mean: 

How to sum the count value using SAP HANA SQLScript in CV ?

former_member435389
Participant
0 Kudos

Hi Experts,

[1] SUM outside

select

COMP,

SUM( case when COMP = '1000' then count( "PERNR" ) else 0 end ) as "NUM"

from tab

;

[2] SUM inside

select

COMP,

case when COMP = '1000' then SUM( count( "PERNR" ) ) else 0 end as "NUM"

from tab

;

All got the same error : "SAP DBTech JDBC: [279]: group function is nested: ......."

So, how to sum the result of count value in one select statement ?

Jörg_Brandeis
Contributor

Hi Wei,

i don't understand the requirement. Can you give us some sample data and the expected result?

And one more ask that would make answering your questions easier and more fun: Please take the time to format the code cleanly and with the right tool:

Then it could look like this:

--[1] SUM outside
SELECT COMP,
       SUM( CASE WHEN comp = '1000' THEN COUNT( "PERNR" ) 
                                    ELSE 0 END ) AS "NUM"
  FROM tab;

--[2] SUM inside
SELECT comp,
       CASE WHEN comp = '1000' THEN SUM( COUNT ("PERNR") )
                               ELSE 0 END AS "NUM"
  FROM tab;

With best regards,

Jörg

Accepted Solutions (0)

Answers (0)