Sum of columns

From: janek12(at)web(dot)de
To: pgsql-general(at)postgresql(dot)org
Subject: Sum of columns
Date: 2013-09-09 01:12:49
Message-ID: trinity-69c71490-7340-4763-9035-24b30bf1eafd-1378689169187@3capp-webde-bs23
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Hi,&nbsp;</div>

<div>&nbsp;</div>

<div>this is my query:</div>

<div><span style="font-family: Verdana, sans-serif, Arial, &#39;Trebuchet MS&#39;; font-size: 13px; line-height: 1.6em;">SELECT user,</span></div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; sum(CASE WHEN lev &gt;= 50 AND lev &lt; 70&nbsp;THEN 1 ELSE 0 END) as a,<br/>
&nbsp; &nbsp; &nbsp; &nbsp; sum(CASE WHEN lev &gt;= 70 AND lev &lt; 80 THEN 1 ELSE 0 END) as b,<br/>
&nbsp; &nbsp; &nbsp; &nbsp; sum(CASE WHEN lev &gt;= 80 AND lev &lt;= 90<span style="font-family: Verdana, sans-serif, Arial, &#39;Trebuchet MS&#39;; font-size: 13px; line-height: 1.6em;">&nbsp;THEN 1 ELSE 0 END) as c,</span></div>

<div>&nbsp; &nbsp; &nbsp; &nbsp; sum(CASE WHEN lev &gt; 90 THEN 1 ELSE 0 END) as d,<br/>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;(SELECT a&nbsp;+ b&nbsp;+ a&nbsp;+ d) AS matches<br/>
&nbsp; &nbsp; &nbsp; &nbsp; FROM t_temp_fts&nbsp;<br/>
&nbsp; &nbsp; &nbsp; &nbsp; GROUP BY user&#39;</div>

<div>&nbsp;</div>

<div>I like to add up the 4 columns a,b,c and d of every user, but it doesn&#39;t work like this.</div>

<div>Does anyone know a solution</div>

<div>&nbsp;</div>

<div>Janek Sendrowski</div></div></body></html>

Attachment Content-Type Size
unknown_filename text/html 1.2 KB

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Curvey 2013-09-09 01:29:45 Re: Sum of columns
Previous Message Bret Stern 2013-09-08 23:51:10 Re: Call for design: PostgreSQL mugs