aggregate functions in "SELECT"

From: Gerald Cheves <gcheves(at)verizon(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: aggregate functions in "SELECT"
Date: 2013-12-03 21:44:07
Message-ID: 529E50A7.3000702@verizon.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Dear Colleagues,

How can I use the COUNT variable and the COL_YES variable to calculate a
percentage COL_YES/COUNT*100?

This operation isn't allowed in the "SELECT" statement.

Thanks

Select g.STATE,
g.COMPANY,
g.MODEL,
count(g.MODEL) as COUNT,
coalesce(sum(case when COLORS = 'Yes' then 1 else 0 end),0) as
COL_YES
from gentech_12_13 as g
where MODEL = '0387' and COMPANY = 'ACME'
group by g.STATE, g.COMPANY, g.MODEL
;

--
siamo arrivati sani e salvi

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Vik Fearing 2013-12-03 22:08:01 Re: aggregate functions in "SELECT"
Previous Message David Johnston 2013-12-03 16:30:15 Re: Add full object name to tag field