Re: Sum of columns - Mailing list pgsql-general

From Chris Curvey
Subject Re: Sum of columns
Date
Msg-id CADfwSsDc3Fgo=_x94Q1=i-fgG7sHpQyGLz3dG78qP=Qz+XwNVw@mail.gmail.com
Whole thread Raw
In response to Sum of columns  (janek12@web.de)
List pgsql-general
does 
       sum (case when lev >= 50 then 1 else 0 end) as matches

do what you want?


On Sun, Sep 8, 2013 at 9:12 PM, <janek12@web.de> wrote:
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



--
The person who says it cannot be done should not interrupt the person who is doing it.  -- Chinese Proverb

pgsql-general by date:

Previous
From: janek12@web.de
Date:
Subject: Sum of columns
Next
From: "Tomas Vondra"
Date:
Subject: Re: Sum of columns