Re: Sum of columns

From: Marc Mamin <M(dot)Mamin(at)intershop(dot)de>
To: "'janek12(at)web(dot)de'" <janek12(at)web(dot)de>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Sum of columns
Date: 2013-09-09 12:12:29
Message-ID: B6F6FD62F2624C4C9916AC0175D56D880CE19DF8@jenmbs01.ad.intershop.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi,

in addition to the others comments, you can also remove " ELSE 0 " from your query.
It will result in <NULL> values that are discarded by SUM.

regards,

Marc Mamin

From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of janek12(at)web(dot)de
Sent: Montag, 9. September 2013 03:13
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Sum of columns

Hi,

this is my query:
SELECT user,
sum(CASE WHEN lev >= 50 AND lev < 70 THEN 1 ELSE 0 END) as a,
sum(CASE WHEN lev >= 70 AND lev < 80 THEN 1 ELSE 0 END) as b,
sum(CASE WHEN lev >= 80 AND lev <= 90 THEN 1 ELSE 0 END) as c,
sum(CASE WHEN lev > 90 THEN 1 ELSE 0 END) as d,
(SELECT a + b + a + d) AS matches
FROM t_temp_fts
GROUP BY user'

I like to add up the 4 columns a,b,c and d of every user, but it doesn't work like this.
Does anyone know a solution

Janek Sendrowski

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message fumihisa.suzuki 2013-09-09 12:55:38 Hello,
Previous Message Oliver Kohll - Mailing Lists 2013-09-09 11:34:47 Making substrings uppercase