From: | "Janek Sendrowski" <janek12(at)web(dot)de> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: devide and summarize sql result (all) |
Date: | 2013-08-16 09:55:07 |
Message-ID: | trinity-b4717b2c-c411-449d-a463-ad5238e1a3ab-1376646907197@3capp-webde-bs15 |
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>
<div>Thanks for your Answers,</div>
<div> </div>
<div>my problem is, that there is no column with the name 'percentage'.</div>
<div>It's just a result of my query. So how can I use it anyway?</div>
<div>Should I just store the result in a record variable and do another query?</div>
<div> </div>
<div>Janek</div>
<div>
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Gesendet:</b> Freitag, 16. August 2013 um 00:24 Uhr<br/>
<b>Von:</b> bricklen <bricklen(at)gmail(dot)com><br/>
<b>An:</b> "Janek Sendrowski" <janek12(at)web(dot)de><br/>
<b>Cc:</b> "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org><br/>
<b>Betreff:</b> Re: [GENERAL] devide and summarize sql result (all)</div>
<div name="quoted-content">
<div>
<div class="gmail_extra">
<div class="gmail_quote">On Thu, Aug 15, 2013 at 1:51 PM, Janek Sendrowski <span><<a href="janek12(at)web(dot)de" target="_parent">janek12(at)web(dot)de</a>></span> wrote:
<blockquote class="gmail_quote" style="margin: 0.0px 0.0px 0.0px 0.8ex;border-left: 1.0px solid rgb(204,204,204);padding-left: 1.0ex;">
<div>
<div style="font-family: Verdana;font-size: 12.0px;">
<div>Hi,<br/>
<br/>
My sql query results sth. like this:<br/>
<br/>
user percentage<br/>
franz 78%<br/>
smith 98%<br/>
franz 81%<br/>
jason 79%</div>
<div>smith 89%</div>
<div>smith 85%</div>
<div>smith 99%</div>
<div> </div>
<div>Now I'd like to summarize the percentages oder every user like this.</div>
<div>smith</div>
<div>2 matches 95-100%</div>
<div>2 matches 85-95%</div>
<div>0 mathes 75-85%</div>
<div> </div>
<div>franz</div>
<div>0 mathes 95-100%</div>
<div>...</div>
</div>
</div>
</blockquote>
</div>
</div>
<div class="gmail_extra">A CASE statement should work, if you are willing to hard-code the list of expressions.<br/>
<br/>
SELECT username,<br/>
sum(case when avg between 76 and 85 then 1 else 0 end) as "76 to 85",<br/>
sum(case when avg between 86 and 95 then 1 else 0 end) as "86 to 95",<br/>
sum(case when avg > 95 then 1 else 0 end) as ">95"<br/>
FROM yourtable<br/>
GROUP BY username</div>
<div class="gmail_extra"> </div>
</div>
</div>
</div>
</div>
</div></div></body></html>
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/html | 2.6 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | salah jubeh | 2013-08-16 11:24:32 | Re: devide and summarize sql result (all) |
Previous Message | Albe Laurenz | 2013-08-16 07:31:33 | Re: SSL connection has been closed unexpectedly |