How to get all the sums of 'SUM'

Asked

Viewed 63 times

1

Good evening everyone, I would like to sum up with the 3 (SUM CASE) below.

SELECT SUM(CASE WHEN (a==b 2 THEN 1 ELSE 0 END) AS qtdDba, SUM(CASE WHEN (a==b 5 THEN 1 ELSE 0 END) AS qtdDev, SUM(CASE WHEN (a==b 10 THEN 1 ELSE 0 END) AS qtdAnalista /*Porem com esse sum abaixo nao soma os 3 valores acima, tem alguma maneira de somar esses 3 valores sem utilizar subselect*/ SUM(1) as totalSum FROM TABELA........

  • Your CASE doesn’t seem functional...

  • Is your case working? you need to detail the problem in detail in the statement. see for example case: http://sqlfiddle.com/#! 4/91262/7

1 answer

0

I believe you want to add up the values this way:

SELECT

 SUM(CASE WHEN (a==b 2 THEN 1 ELSE 0 END) +
 SUM(CASE WHEN (a==b 5 THEN 1 ELSE 0 END) +
 SUM(CASE WHEN (a==b 10 THEN 1 ELSE 0 END) 

 /*Porem com esse sum abaixo nao soma os 3 valores acima, tem alguma maneira 
 de somar esses 3 valores sem utilizar subselect*/
 SUM(1) as totalSum
FROM
    TABELA........

Browser other questions tagged

You are not signed in. Login or sign up in order to post.