Re: using to_number() in a select query with ranges

From: Mike Ellsworth <younicycle(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: using to_number() in a select query with ranges
Date: 2009-01-27 23:04:32
Message-ID: 219951fd0901271504k26287414t3e4d048de4582d49@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

> select count (to_number("value",'9D9')) as the_number where fk_lu_request =
> 872 ;
>
> But I want to be able to split up all the results into ranges eg <6, 6-7, 7-8
>>8 etc.
>
> I want to do the equivalent of this sort of concept.
>
> select
> '6-6.5' as XAxes_text, count (value) as count, ,'1' as display_order
> From clin_requests.vwResults where fk_lu_request = 872
> and to_number("value",'9D9')) between 6-7;
>
> but this dosn't work, and I've obviously got the syntax wrong. I've read the
> docs and tried dozens of permutations to no avail.
>

Might be a little easier battle if you use trunc() where you have
'between 6-7'....
so maybe trunc(to_number("value",'9D9'))

Here is one that seems similar to your intent that gets the count on
archery scoring, used for a bar graph.

SELECT "cnt_score"."val" AS val, count("cnt_score"."val") AS counter
FROM "examples"."cnt_score" GROUP BY "cnt_score"."val" ORDER BY val
ASC

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Nico Callewaert 2009-01-28 10:43:24 JOIN vs. LEFT JOIN
Previous Message richard terry 2009-01-27 20:50:13 using to_number() in a select query with ranges