Re: Counts and percentages and such

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: jackassplus <jackassplus(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Counts and percentages and such
Date: 2009-12-08 22:02:38
Message-ID: dcc563d10912081402m44fa159ci321c0c32caafa70@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Dec 8, 2009 at 2:21 PM, jackassplus <jackassplus(at)gmail(dot)com> wrote:
> <snip>
>> select coalesce(col,'Null'),
>> (count(coalesce(col,'Null'))::numeric/(select count(*) from
>> some_table))*100 from some_table group by col;
>>  coalesce |        ?column?
>> ----------+-------------------------
>>  Null     | 13.33333333333333333300
>>  N        | 20.00000000000000000000
>>  A        | 26.66666666666666666700
>>  L        | 40.00000000000000000000
>>
>> Note that it works, but we get long ugly numbers, and the column has
>> no name (?column?).  Let's fix that:
>
> What does ::numeric signify?
> I'm using the jdbc driver from http://jdbc.postgresql.org/ in SQuirreL
> and it asks me for the value of :numeric.

::numeric is a cast in pgsql. The long version looks like:

cast (col as numeric)

which might work better. I'm no expert on the jdbc driver so your
question may require someone else to give a definitive answer.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2009-12-08 22:04:20 Re: Counts and percentages and such
Previous Message erobles 2009-12-08 21:25:23 Linking pg_config (postgres 8.4 in SCO 5.0.7)