From: | Chris Curvey <chris(at)chriscurvey(dot)com> |
---|---|
To: | janek12(at)web(dot)de |
Cc: | pgsql <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Sum of columns |
Date: | 2013-09-09 01:29:45 |
Message-ID: | CADfwSsDc3Fgo=_x94Q1=i-fgG7sHpQyGLz3dG78qP=Qz+XwNVw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)web(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Tomas Vondra | 2013-09-09 02:16:33 | Re: Sum of columns |
Previous Message | janek12 | 2013-09-09 01:12:49 | Sum of columns |