Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Using count(distinct(to_char(xxx,ddd) in Oralce sql

HI All,

I am trying to count the number of days a certain event happens inside my
database,
an I am not sure the best way to do it. I have a series of values entered
every 1/2
hour and I want to see the number of days of which a values is above certain
criteria.

I am using an oracle database, and have tried various methods of counting
using
the distinct command. I know the counting (to_char(xxx,'dd') gives me the
distinct
number of days of the month but I want the number of actual days. So I am
wordering
if (to_char(xxx,'ddd') will only give me the distinct number of days of all
year
not a combined total over a range of years.

Am I understading the distinct count bit right and is this the right way
to go
about it ??

thanks in advance,

Peter
[877 byte] By [Peter Piper] at [2007-11-9 21:11:05]
# 1 Re: Using count(distinct(to_char(xxx,ddd) in Oralce sql
Perhaps I am mis-understanding you, but if you want to know the number of
days between two dates, the following should work:

SELECT TO_DATE('30-MAY-03') - TO_DATE('13-MAY-03') AS Date_Difference
FROM dual;

-Good Luck

"Peter Piper" <pet5pan@netscape.net> wrote:
>
>HI All,
>
>I am trying to count the number of days a certain event happens inside my
>database,
>an I am not sure the best way to do it. I have a series of values entered
>every 1/2
>hour and I want to see the number of days of which a values is above certain
>criteria.
>
>I am using an oracle database, and have tried various methods of counting
>using
>the distinct command. I know the counting (to_char(xxx,'dd') gives me the
>distinct
>number of days of the month but I want the number of actual days. So I am
>wordering
>if (to_char(xxx,'ddd') will only give me the distinct number of days of
all
>year
>not a combined total over a range of years.
>
>Am I understading the distinct count bit right and is this the right way
>to go
>about it ??
>
>thanks in advance,
>
>Peter
dowl at 2007-11-11 23:51:47 >