From: | Sean Davis <sdavis2(at)mail(dot)nih(dot)gov> |
---|---|
To: | Josep Sanmart í <josep(dot)sanmarti(at)openwired(dot)net>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How to join several selects |
Date: | 2005-08-24 14:03:26 |
Message-ID: | BF31F66E.D0DF%sdavis2@mail.nih.gov |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 8/24/05 9:46 AM, "Josep Sanmartí" <josep(dot)sanmarti(at)openwired(dot)net> wrote:
> Hello,
> I have a 'big' problem:
> I have the following table users(name, start_time, end_time), a new row
> is set whenever a user logs into a server. I want to know how many
> users have logged in EVERYDAY between 2 different dates. The only idea
> that I have is making several select (one for each day):
> SELECT COUNT(name) FROM users WHERE start_time between "startDate"
> and "startDate+1"
> SELECT COUNT(name) FROM users WHERE start_time between "startDate+1"
> and "startDate+2"
> ...
> I would like to know if its possible to make it in 1 sql statement or
> just which is the best efficient way to solve it.
> By the way, I use Postgres 7.4.
See:
http://www.postgresql.org/docs/8.0/interactive/sql-select.html#SQL-UNION
like:
SELECT COUNT(name) FROM users WHERE start_time between "startDate"
and "startDate+1"
union
SELECT COUNT(name) FROM users WHERE start_time between "startDate+1"
and "startDate+2"
Sean
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Glaesemann | 2005-08-24 14:14:22 | Re: How to join several selects |
Previous Message | Rod Taylor | 2005-08-24 13:52:04 | Re: How to join several selects |