Re: Need help writing SQL statement

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: Need help writing SQL statement
Дата
Msg-id 1120071060.8208.119.camel@state.g2switchworks.com
обсуждение исходный текст
Ответ на Re: Need help writing SQL statement  (Jeffrey Melloy <jmelloy@visualdistortion.org>)
Ответы Re: Need help writing SQL statement  (D A GERM <dgerm@shepherd.edu>)
Список pgsql-general
On Wed, 2005-06-29 at 13:20, Jeffrey Melloy wrote:
> 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)


Note that an index created on date_part('hour',timestamp) should be
usable here as long as it's selectable enough.

В списке pgsql-general по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: Passing a table name to a function for dynamic queries....
Следующее
От: Matt Miller
Дата:
Сообщение: Re: CVS Build - No Doc