Re: Need help writing SQL statement

From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: D A GERM <dgerm(at)shepherd(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Need help writing SQL statement
Date: 2005-06-29 18:20:01
Message-ID: 42C2E651.2080108@visualdistortion.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

D A GERM wrote:

> I have been trying to write an sql statement that returns the same
> hours in a time stamp no matter what the date.
> I can to pull same hours on the the same days but have not been able
> to figure out how to pull all the same hours no matter what the date.
>
> Here is the one sql statement I have been using:
> SELECT COUNT(time_stamp) FROM table WHERE time_stamp BETWEEN
> 20050629100000 and 20050631100000;
>
> Any help would be appreciated.
>
> Thanks in advanced for any help
>
You can do something like
SELECT count(*)
FROM table
where date_part('hour', timestamp) in (10, 11)

This query is going to require a seq scan, so if you're running it
frequently you can make an index on date_part('hour', timestamp)

Jeff

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matt Miller 2005-06-29 18:28:29 Re: CVS Build - No Doc
Previous Message Greg Patnude 2005-06-29 17:25:15 Passing a table name to a function for dynamic queries....