Re: percentages of a column - Mailing list pgsql-sql

From Gregory Stark
Subject Re: percentages of a column
Date
Msg-id 87ved6krgw.fsf@oxford.xeocode.com
Whole thread Raw
In response to percentages of a column  (Andreas <maps.on@gmx.net>)
List pgsql-sql
"Andreas" <maps.on@gmx.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 "%"
frombasket group by fruit_nameorder by "%";
 
fruit_name | count |  %  
------------+-------+-----Bananas    |     5 | 10%Apples     |    15 | 30%Oranges    |    30 | 60%
(3 rows)

--  Gregory Stark EnterpriseDB          http://www.enterprisedb.com



pgsql-sql by date:

Previous
From: Andreas
Date:
Subject: percentages of a column
Next
From: dBHS Jakarta
Date:
Subject: Query Problem from FoxPro???