Re: percentages of a column
- From: Gregory Stark <stark(at)enterprisedb(dot)com>
- To: "Andreas" <maps(dot)on(at)gmx(dot)net>
- Cc: "PostgresSQL list" <pgsql-sql(at)postgresql(dot)org>
- Subject: Re: percentages of a column
- Date: Sat, 30 Jun 2007 05:15:43 +0100
- Message-id: <87ved6krgw.fsf@oxford.xeocode.com> <text/plain>
"Andreas" <maps(dot)on(at)gmx(dot)net> writes:
> Example:
>
> Fruit Count %
> --------------------------
> Bananas 5 10%
> Apples 15 30%
> Oranges 30 60%
select fruit_name, count(*),
round(count(*)::numeric / (select count(*) from basket) * 100, 0)::text||'%' as "%"
from basket
group by fruit_name
order by "%";
fruit_name | count | %
------------+-------+-----
Bananas | 5 | 10%
Apples | 15 | 30%
Oranges | 30 | 60%
(3 rows)
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Home |
Main Index |
Thread Index