pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gregory Stark <stark@enterprisedb.com>
To: Andreas <maps.on@gmx.net>
Cc: PostgresSQL list <pgsql-sql@postgresql.org>
Subject: Re: percentages of a column
Date: Sat, 30 Jun 2007 05:15:43 +0100
Message-ID: <87ved6krgw.fsf@oxford.xeocode.com> (raw)
In-Reply-To: <4685BC84.2090106@gmx.net>
References: <4685BC84.2090106@gmx.net>

"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 "%"
  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




view thread (2+ messages)

Message-ID: <87ved6krgw.fsf@oxford.xeocode.com>
Permalink:  ../87ved6krgw.fsf@oxford.xeocode.com/
Also on:    postgresql.org/message-id/87ved6krgw.fsf@oxford.xeocode.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: stark@enterprisedb.com, maps.on@gmx.net
  Subject: Re: percentages of a column
  In-Reply-To: <87ved6krgw.fsf@oxford.xeocode.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox