Wednesday, March 28, 2012

Query help

I have a table with one column that has all negative values.
IO
-70.72
-72.93
-67.38
-65.05
-62.31
-65.52
-69.98
now we have to find that how many samples of IO are between
-50 to -40 range
-60 to -70 range
-70 to -60 range
How can I accomplish this. Thanks for your help.This should give you something to think about.
SELECT CONVERT(int, ThatColumn / 10) * 10 as RangeStart,
count(*) as Rows
FROM TheTable
GROUP BY CONVERT(int, ThatColumn / 10)
ORDER BY RangeStart
Roy Harvey
Beacon Falls, CT
On Fri, 7 Sep 2007 10:00:08 -0700, Shan
<Shan@.discussions.microsoft.com> wrote:
>I have a table with one column that has all negative values.
>IO
>-70.72
>-72.93
>-67.38
>-65.05
>-62.31
>-65.52
>-69.98
>now we have to find that how many samples of IO are between
>-50 to -40 range
>-60 to -70 range
>-70 to -60 range
>How can I accomplish this. Thanks for your help.|||This doesn't work. Any other ideas.
"Shan" wrote:
> I have a table with one column that has all negative values.
> IO
> -70.72
> -72.93
> -67.38
> -65.05
> -62.31
> -65.52
> -69.98
> now we have to find that how many samples of IO are between
> -50 to -40 range
> -60 to -70 range
> -70 to -60 range
> How can I accomplish this. Thanks for your help.|||On Fri, 7 Sep 2007 15:02:02 -0700, Shan
<Shan@.discussions.microsoft.com> wrote:
>This doesn't work. Any other ideas.
CREATE TABLE TestRanges (d decimal (13,2) NOT NULL)
INSERT TestRanges VALUES (-70.72)
INSERT TestRanges VALUES (-72.93)
INSERT TestRanges VALUES (-67.38)
INSERT TestRanges VALUES (-65.05)
INSERT TestRanges VALUES (-62.31)
INSERT TestRanges VALUES (-65.52)
INSERT TestRanges VALUES (-69.98)
SELECT CONVERT(int, d / 10) * 10 as RangeStart,
count(*) as Rows
FROM TestRanges
GROUP BY CONVERT(int, d / 10)
ORDER BY RangeStart
RangeStart Rows
-- --
-70 2
-60 5
Is this not close?
Roy Harvey
Beacon Falls, CT

No comments:

Post a Comment