Sum of columns - Mailing list pgsql-general

From janek12@web.de
Subject Sum of columns
Date
Msg-id trinity-69c71490-7340-4763-9035-24b30bf1eafd-1378689169187@3capp-webde-bs23
Whole thread Raw
Responses Re: Sum of columns
Re: Sum of columns
Re: Sum of columns
Re: Sum of columns
List pgsql-general
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

pgsql-general by date:

Previous
From: Bret Stern
Date:
Subject: Re: Call for design: PostgreSQL mugs
Next
From: Chris Curvey
Date:
Subject: Re: Sum of columns