Re: Oracle SQL-Group by/decode

From: vze <vze3myxh_at_verizon.net>
Date: Wed, 20 Feb 2002 23:05:57 GMT
Message-ID: <pZVc8.10443$9H5.6657_at_nwrddc01.gnilink.net>


Wouldn't this work?

SELECT to_char(time,'HH24') start_hour, to_char(time + 1/24,'HH24') end_hour, count(id)
from tables
where blah blah
group by to_char(time,'HH24')

Off the top of my head and not tested.

In article <GKVc8.52083$p5.8215006_at_news1.rdc1.nj.home.com>, "David Howland" <dhowland123_at_home.com> wrote:

> Hi all:
> I am trying to write an SQL in Oracle and could use some help. I have a
> table
> that has 2 columns (lets say), col1 is a timestamp and column 2 is an
> id. Using
> a join to another table I can extract a count of the id's I want and
> want to group by
> a range of times. For example:
>
> time id
> 01:25 1
> 01:45 2
> 01:55 3
> 02:25 4
> 03:15 5
> 04:25 6
> 05:35 7
> 06:45 8
> 07:00 9
> 08:15 10
> 09:25 11
>
>
>
>
> Okay, so in conclusion I need an SQL that will get a count of the number
> of id's by
> a range and return something like
>
> time occurrences
>
> 01:00 - 02:00 3
> 02:00 - 03:00 1
> 03:00 - 04:00 1
> 04:00 - 05:00 1
>
>
> etc....
>
>
> I have tried Oracle's decode and it doesn't seem that I can test ranges
> of data in the condition and I can't find examples of 'case' anywhere,
> nor get it to work. Group doesn't appear to allow this kind of
> functionality. Any thoughts?
> thanks, Dave
>
>
>
Received on Thu Feb 21 2002 - 00:05:57 CET

Original text of this message